Does anyone know why I’m getting a compiler error for the equality operation on a class that has a 3 way operator override? I'm using VS 2019.
class Rectangle
{
public:
constexpr Rectangle(const int width, const int height) :
width{ width }, height{ height } { }
auto operator<=>(const Rectangle& rhs) const {
return width * height <=> rhs.width * rhs.height;
}
int width;
int height;
};
void Test() {
Rectangle r1(5, 10);
Rectangle r2(10, 5);
auto ret1 = r1 < r2;
auto ret2 = r1 <= r2;
auto ret3 = r1 == r2; // error on this line but previous two are good
}
I'm getting an error for the line noted above: NativeConsoleApp.cpp(68,20): error C2676: binary '==': 'Rectangle' does not define this operator or a conversion to a type acceptable to the predefined operator
Edit: Note the explanation at non-defaulted operator <=> doesn't generate == and != in C++20 doesn't address why the inequality operators work but not the equality operator.
Edit: The link above makes sense now after rereading it a month later.