- объекты разных классов не равны;
- объекты одного и того же класса сравниваются с использованием логики, специфичной для этого класса.
Код: Выделить всё
struct A
{
bool operator==(const A& x) const { return true; }
};
struct B : A
{
int i;
explicit B(int _i = 0) : i{_i} {}
bool operator==(const B& x) const { return i == x.i; }
};
struct C : B
{
float f;
explicit C(float _f) : f{_f} {}
bool operator==(const C& x) const { return abs(f - x.f) < 0.1; }
};
template
bool operator==(const X& x, const Y& y) { return false; }
Подробнее здесь: https://stackoverflow.com/questions/798 ... or-correct
Мобильная версия