I tried two variants of defining operator<=>
,
variant A uses = default
. In consequence I am able to use operator ==
.
But if I implement operator<=>
by hand in variant B, the comparison x1 == x2
stops working.
Why is this the case? It it stated this way in the C++20 standard? I could not find any explanation so far.
For me operator<=>
is a function, whether it is defaulted or not. I expect no difference between A and B.
Code:
#include <iostream>
class X {
public:
int y;
/*A*/ inline std::strong_ordering operator<=>(const X& another) const = default;
/*B*/ //inline std::strong_ordering operator<=>(const X& another) const { return y <=> another.y; }
};
int main()
{
using std::cout;
using std::endl;
X x1;
x1.y = 5;
X x2;
x2.y = 7;
cout << "x1 == x2: " << (x1 == x2) << endl;
cout << "x1 == x2: " << (x1 <=> x2 == 0) << endl;
return 0;
}
1