Consider the following class that contains a conversion function for the type std :: string:
class SomeType { public: SomeType(char *value) { _str = value; } operator std::string() { return std::string(_str); } private: char *_str; };
The following fragment cannot be compiled with an error: not a single "==" operator matches these operands
int main(int argc, char* argv[]) { SomeType a("test"); if (a == std::string("test"))
I understand that I can define an operator == method that accepts the std :: string operand, but why does the conversion function not work?
source share