Closed
Description
struct P {
#if 1
template<class S>
bool operator==(const S &) const;
#else
template<class S>
friend bool operator==(const P &, const S &);
#endif
};
struct A : public P {};
struct B : public P {};
bool check(A a, B b) {
return a == b;
}
The friend
function works just fine, but the member function dies with
<source>:15:14: error: use of overloaded operator '==' is ambiguous (with operand types 'A' and 'B')
return a == b;
~ ^ ~
<source>:4:10: note: candidate function [with S = B]
bool operator==(const S &) const;
^
<source>:4:10: note: candidate function (with reversed parameter order) [with S = A]
GCC and MSVC accept both. https://godbolt.org/z/9hj9554fn
Metadata
Metadata
Assignees
Type
Projects
Status
Done