I ll try to explain with some code then. I am trying to simulate how I believe string works:
Code:
class myString
{
char* cStr;
...
}
bool operator==(const myString& str, const char* cstr)
{
if (strcmp(str.cStr, cstr) == 0)
return true;
else
return false;
}
If you do this:
Code:
char * szTest = "Hello World";
if((myString)szTest == "Hello World")
cout << "True";
Won't this code be executed:
Code:
if (strcmp(str.cStr, cstr) == 0)
thus getting an error, since str is not a real myString, just a char* casted to a myString?
Well, obviously I am wrong since this has been tested. But I am not understanding it completely.
If you could compare a char* with another char* why don't overload the operator == for that occasion and require a cast to string for this to work?