using user-defined conversions with implicit conversions in comparisons
问题 I am struggling to understand why the following code does not allow an implicit conversion to occur. #include <string> using namespace std; struct HasConversionToString { HasConversionToString(const string& s_) : s{s_} {} string s; operator const string&() const { return s; } }; int main() { string s{"a"}; HasConversionToString obj{"b"}; return s < obj; } Both clang and gcc fail to find a valid way to compare the two objects with errors along the lines of: clang++ -std=c++14 -Wall -Wextra