Jump to content
  • Advertisement
Sign in to follow this  
The C modest god

Unity string into MyClass

This topic is 4327 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

Advertisement
Create a constructor for MyClass which takes a single argument of type const char*. It is advised to do the same with the type std::string as well.

The constructor will be used whenever a string is used in place of MyClass.

Share this post


Link to post
Share on other sites
Single parameter constructors enable implicit conversion from their parameter type to their class, unless they are marked with the explicit keyword. Give MyClass a constructor taking a char* (and possibly also a constructor taking a const std::string&). Please keep in mind that only one user-defined implicit conversion is performed. So if you only had a constructor taking a const std::string& it wouldn't work when you give it a char*, since it would take two conversions to get MyClass.

Share this post


Link to post
Share on other sites

This topic is 4327 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!