나는 종종 !(*this == rhs)
을 반환하여 빠른 operator!=
쓰기, 예를 들면 : 나는이 일을 어떤 명백한 문제를 볼 수는 없지만 는 신속하고 더러운 연산자 = 내 수업에서
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);
}
};
내가 누군가 물어 줄 알았는데 어떤 것도 안다.
+1을 읽을 것입니다. 나는 이것을 깔끔하게 발견한다. – Perpetualcoder