C++: Overload != When == Overloaded
- by Mark W
Say I have a class where I overloaded the operator == as such:
Class A {
...
public:
bool operator== (const A &rhs) const;
...
};
...
bool A::operator== (const A &rhs) const {
..
return isEqual;
}
I already have the operator == return the proper Boolean value. Now I want to extend this to the simple opposite (!=). I would like to call the overloaded == operator and return the opposite, i.e. something of the nature
bool A::operator!= (const A &rhs) const {
return !( this == A );
}
Is this possible? I know this will not work, but it exemplifies what I would like to have. I would like to keep only one parameter for the call: rhs. Any help would be appreciated, because I could not come up with an answer after several search attempts.