Код: Выделить всё
#include
struct A
{
int n;
auto operator(A const& other) const
{
if (n < other.n)
{
return std::strong_ordering::less;
}
else if (n > other.n)
{
return std::strong_ordering::greater;
}
else
{
return std::strong_ordering::equal;
}
}
// compile error if the following code is commented out.
// bool operator==(A const& other) const
// { return n == other.n; }
};
int main()
{
A{} == A{};
}
Почему я должен предоставить operator == , когда operator достаточно?
Подробнее здесь: https://stackoverflow.com/questions/682 ... -is-enough