c++ - Type conversion for std::strings -


is possible have global type conversion operator functions class? looking way expose const char* std::string. tried defining global operator doesn't compile. quick search , looking @ cpp reference these user defined conversion needs member http://en.cppreference.com/w/cpp/language/cast_operator.

is there kind of clean (or hacks) way of passing std::string methods accepts const char* without using c_str().

background:

i working on cross platform , windows. of classes uses atl::cstring. , changing them use std::string's. invoking c_str fine, in unit test code there seem of call every line , every args, trying lazy here.

just user-defined types can define own constructors, user-defined types can define whether implicitly convertible other types (or other types via non-explicit constructors). no, cannot force implicit conversion std::string const char* outside class.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -