私のクラスでは、operator!=
を返すことで簡単に書くことがよくあります!(*this == rhs)
。
class Foo
{
private:
int n_;
std::string str_;
public:
...
bool operator==(const Foo& rhs) const
{
return n_ == rhs.n_ && str_ == rhs.str_;
}
bool operator!=(const Foo& rhs) const
{
return !(*this == rhs);
}
};
これを行うことで明らかな問題は見られませんが、誰かが知っているかどうか尋ねたいと思いました。