RWCString str = "Y";
str.append("ES");
if("YES" == str)
cout << "YES == str" << endl;
if(str == "YES")
cout << "str == YES" << endl;
How does the implicit conversion take place in both cases? Which one is safe to use? RWCString is a string class which has a constructor taking const char* and an conversion operator to const char*
It is extremely likely that
==is overloaded for comparisons betweenconst char*andRWCString.Otherwise either
stris converted toconst char *or the calls are ambiguous:str == "YES"is ambiguous if there is an external or memberoperator==comparing twoRWCStrings."YES" == stris ambiguous if there is an externaloperator==comparing twoRWCStrings.(assuming that the arguments to the
operator==are passed normally -- either through a copy, or aconstreference).