Since in C ++ string literals are of type const char[] (also called a constant string with a zero end), and not std::string , not to mention String (whatever that is).
There is a built-in operator== comparing two char* by comparing their addresses. Since arrays are implicitly converted to pointers to their first elements (because you guessed it correctly, the C legacy), this statement comes in and compares the addresses of these literals in memory.
Assuming your String class has an implicit conversion constructor from const char* ( String::String(const char*) ), you can convert one of the two to String . Then the other line will be converted implicitly:
String("cobble") == "stone"
(If operator== overloads are not required for efficiency, they take String and a const char* values. If they are provided, they are included.)
source share