
please wait
if(c=="Hello! How are you?")
c==String("Hello! How are you?")
or just throw away the char* operator and add a c_str() function (like in std::string).
1) Why does compiler even think of using char* == char* , when on the left hand side it is an object of my class and not a string.? |
c=="Hello! How are you?"
ambiguous; you get the error because the compiler does not know which to use. String(char s[])
implicitly defines a conversion of char* to String. You can declare the constructor to be "explicit" to prevent its implicit use, but you probably still want conversion of char* to String. You probably don't really want conversion of String to char* though, so I would recommend removing the char* conversion operator in favor of a c_str() as hamsterman suggest.2) I agree that I should have used c==String("Hello! How are you?"). Thanks for making me realize my mistake. But in this case, why didnt the compiler give error something like "== not defined to use a constant string on right side".? |
Why the error is totally diferent.. i.e. by what logic, compiler starts thinking which of the two overloads [char*==char* and string == string ] to use? |