在我的课堂上,我经常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);
}
};
我看不出这样做有任何明显的问题,但我想我会问是否有人知道。