Этот код компилируется нормально, как и ожидалось:
Код: Выделить всё
#include
struct X
{
int Dummy = 0;
auto operator(const X&) const = default; // Default implementation
};
int main()
{
X a, b;
a == b; // OK!
return 0;
}
Код: Выделить всё
struct X
{
int Dummy = 0;
auto operator(const X& other) const
{
return Dummy other.Dummy;
}
};
Код: Выделить всё
error C2676: binary '==': 'X' does not define this operator or a conversion to a type acceptable to the predefined operator
Я бы оцените объяснение того, почему реализация по умолчанию генерирует оператор == правильно, а пользовательская — нет.
Подробнее здесь: https://stackoverflow.com/questions/587 ... nerate-and