Hi,I get a trouble when I create a class that's a seal class for string manipulate.
I override an operator ==:
bool operator ==(char *pStr);
and I override other operator (char*):
char* operator(char*)();
When I use the operator == like this:
CMyString strTest;
if(strTest == "OK")
{
return true;
}
else
{
return false;
}
I get a compile error, That mean is C++ compiler can distinguish the == operator is either(char* == char*) or (CMyString == char*).
Thanks.
class TString { public:
class TString { public: operator char *(void) { printf("(char *)\n"); return "oups"; } bool operator == (const char *) { printf("==(char *)\n"); return true; } }; int main(void) { TString str; if(str == "Foo") { printf("True\n"); } else { printf("False\n"); } return 0; }