これはベストプラクティスです(この場合):
bool Foo::operator==(const Foo& other) {
return bar == other.bar;
}
// Implementation 1
bool Foo::operator!=(const Foo& other) {
return bar != other.bar
}
// Implementation 2
bool Foo::operator!=(const Foo& other) {
return !(*this == other);
}
>、<、<=、>= などの演算子については、可能であれば実装 2 を使用します。ただし、!= については別のメソッド呼び出しを行わないので実装 1 の方が良いと思いますが、これでよろしいでしょうか?