The following post concerns Visual C++.NET.
The initialization function of a particular class takes a reference to a String (my custom string type). When I try to make the following call:
SomeClass AnObject("Blah.ext");
where the SomeClass constructor declaration looks like this:
SomeClass (String &Filename);
, I get this error:
cannot convert parameter 1 from ''char [9]'' to ''String &''
Now, the String class has a constructor that looks like this:
String(const char *Source);
, but apparently something is different enough between a static char array and a const char pointer that the conversion can''t be implicitly made.
BUT, if I explicitly cast the parameter to a string type, like so:
SomeClass AnObject(String("Blah.ext"));
, it compiles and runs just fine, but I get this warning:
nonstandard extension used : ''argument'' : conversion from ''String'' to ''String &''
, which seems weird, since I obviously intended to pass by reference, and it seems that the reference should be created implicitly and passed without any sort of concern.
SO, here''s the question:
How can I modify the constructors of my String function to correctly create a string from a char[] that can be passed by reference without casting or warning-laden reference creation.
I realize it''s a mouthful. Thanks for any pointers you can provide.
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links