I have a piece of code that implemented the == overload. And I had to use it somewhere negated. But writing !(A == B)
does not seem really clear for the reader. So I implemented this double overloading instead. Does it have any drawbacks of doing it this way? Efficiency wise?:
struct Foo{
bool operator==(const Foo& other) const{
.... //Something that sometimes produces "return false"
return true;
}
bool operator!=(const Foo& other) const{
return !(*this == other);
}
}
Bonus: Why does the compiler not already default implement !=
using the negation of ==
?