Archived

This topic is now archived and is closed to further replies.

Custom String Type Problem

This topic is 5151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

Someclass( const String& thestring)



damn you beat me! anyways my code will work, urs will not, you forgot the ";"

Share this post


Link to post
Share on other sites