The full error messages are: test.cc: In function 'int main()': test.cc:15: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: test.cc:9: note: candidate 1: bool operator==(const B&, const B&) test.cc:6: note: candidate 2: bool B::operator==(const A&) const
This is obvious nonsense. Detailed explanation: There can only be ambiguity if each candidate is better than the other for at least one argument, or they are just as good for all arguments. For overloading purposes the member function is considered to have a first parameter of type const B& corresponding to *this. The two arguments have types B and B, and are rvalues. The first argument must be converted to type const B& (identity conversion sequence) in both cases. The second argument must be converted to type const B& (identity conversion sequence) for the non-member function or const A& (user-defined conversion sequence) for the member function, so the non-member is better. Ben. -- Ben Hutchings For every action, there is an equal and opposite criticism. - Harrison
signature.asc
Description: This is a digitally signed message part