struct BaseA {
auto operator==(const BaseA& other) const {return other.a == a;}
int a;
};
struct B {
int b;
};
struct A: public BaseA {
auto operator==(const B& other) const {return other.b == a;}
};
int main() {
A a{10};
a == a;
return 0;
}
It won't compile:
error: no match for ‘operator==’ (operand types are ‘A’ and ‘A’)
note: candidate: ‘auto A::operator==(const B&) const’
note: no known conversion for argument 1 from ‘A’ to ‘const B&’
Doesn't list BaseA::operator==
as a candidate.
However, if I comment out A::operator==
method, it compiles.
Because of that I thought comparison operators get some special treatment, (sometimes generated for the child class, sometimes not, like those out of rule-of-five), but after a quick search turns out not the case.
Some rules of operator overloading, then?