C++: Overload != When == Overloaded
Posted
by
Mark W
on Stack Overflow
See other posts from Stack Overflow
or by Mark W
Published on 2012-09-04T21:36:13Z
Indexed on
2012/09/04
21:37 UTC
Read the original article
Hit count: 197
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.
© Stack Overflow or respective owner