C++でバイナリ関係演算子をオーバーロードする適切な/標準的な方法は何ですか?
メンバー関数とfriend
フリー関数のどちらを使用するのが良いですか?
例えば:
class X {
public:
...
// Use member function overloads
bool operator==(const X& rhs) const {
return m_text == rhs.m_text;
}
private:
std::string m_text;
};
また:
class X {
public:
...
// Use friend free function overloads
friend bool operator==(const X& lhs, const X& rhs) {
return lhs.m_text == rhs.m_text;
}
private:
std::string m_text;
};