I think this example best illustrates my question:
namespace N {
class C {
public:
friend bool operator==(const C& c, const C& x) {
return true;
}
friend bool f(const C& c, const C& x) {
return true;
}
};
class D {
public:
bool operator==(const D& x) {
bool a = C{} == C{}; // this works
return true;
}
bool f(const D& x) {
bool a = f(C{}, C{}); // this does not work
return true;
}
};
}
I have always viewed overloaded operators as being just like function except for the 'calling syntax' if you will. I just noticed the above difference however in ADL or name lookup rules (I don't know which one).
Can someone explain why the bool operator==(const C& c, const C& x)
is found but the bool f(const C& c, const C& x)
is not?