Dieser Code lässt sich wie erwartet gut kompilieren:
Code: Select all
#include
struct X
{
int Dummy = 0;
auto operator(const X&) const = default; // Default implementation
};
int main()
{
X a, b;
a == b; // OK!
return 0;
}
Code: Select all
struct X
{
int Dummy = 0;
auto operator(const X& other) const
{
return Dummy other.Dummy;
}
};
Code: Select all
error C2676: binary '==': 'X' does not define this operator or a conversion to a type acceptable to the predefined operator
Das würde ich tun Ich freue mich über eine Erklärung, warum die Standardimplementierung „operator==“ korrekt generiert, die benutzerdefinierte Implementierung jedoch nicht.