Consider the following code.
#include
#include
struct SimpleStruct
{
operator std::string () { return value; }
std::
operator< for std::string is a function template. The overloads are:
template
bool operator< (const basic_string& lhs,
const basic_string& rhs);
template
bool operator< (const basic_string& lhs,
const charT* rhs);
template
bool operator< (const charT* lhs,
const basic_string& rhs);
Your call doesn't match any of the available overloads, so they are all removed from a list of candidates. Since no function template was picked as a candidate for resolving the call, there is nothing to convert SimpleStruct to.
template
class String
{
};
template
bool operator< (const String&, const String&) { return true; }
//if a suitable non-template function is available, it can be picked
//bool operator< (const String&, const String&) { return true; }
struct SimpleStruct
{
operator String () { return value; }
String value;
};
int main()
{
String s;
SimpleStruct ss;
s < ss; //the call doesn't match the function template, leaving only the commented-out candidate
}