My class is like:
class X {
public:
:
:
:
operator const char*() const { return "foo"; };
operator std::string() const { return std::string( "foo" ); };
:
:
:
};
My hope was to be able to initialize a std::string implicitly, like this, but huge wall of errors:
string s1( x );
Even explicitly doesn't work:
string s1( (string) x );
However casting x to (const char*)
works fine:
string s1( (const char*) x );
In addition to whatever solution you guys have, any other recommendations for making a type that should be as freely-convertible to and from C-style strings and std:string
? (I already have constructors for X taking const char*
and std::string
as well as an x, and can take assignments from those types.