What is the proper/canonical way of overloading binary relational operators in C++?
Is it better to use member functions, or friend
free functions?
E.g.:
class X {
public:
...
// Use member function overloads
bool operator==(const X& rhs) const {
return m_text == rhs.m_text;
}
private:
std::string m_text;
};
or:
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;
};