Should “operator !=” always be implemented via “operator ==” in C++?
问题 I currently review an old C++ codebase and see a lot of code going like this: bool SomeClass::operator==( const SomeClass& other ) const { return member1 == other.member1 && member2 == other.member2; } bool SomeClass::operator!=( const SomeClass& other ) const { return member1 != other.member1 || member2 != other.member2; } clearly comparison logic is duplicated and the code above will likely have to be changed in two places instead of in one. AFAIK the typical way to implement operator!= is