class classN
{
public:
bool operator== (const classN &o) const {//some logic here};
bool operator!= (const classN &o) const {return !(*this == o);};
};
I see this as the best way to write overloads of operator== and operator!=, as I need to change code only once. however, I've seen in different projects people writing actual code in both overloads. As I mention, I feel it's quite a big downside that if logic will be changed it should be changed in two places, with can leads to a bugs when you will forget to make similar change in other overload. But maybe there are some downsides I'm not aware of writing the way I've shown now, using return !(*this == o);
? Like calling to a operator== overload inside operator!= being too expensive, so it makes sense to write actual code with comparison of the class fields? Or something else?