Why does WrapperString actually compile given the two implicit conversions differ only by their constness
The return type is not the only difference: operator std::string
and operator const std::string
are names of these two functions, and they happen to be different in this case, unlike the names of the get
member functions.
$3[basic]/4:
"A name is a use of [...] conversion-function-id"
$12.3.2.1[class.conv.fct]/1:
conversion-function-id:
operator conversion-type-id
If you'd like, you could call them by those names using plain function call syntax.
std::string s1 = w.operator std::string();
std::string s2 = w.operator const std::string();
std::string s3 = w.get(); // which get?