"Matthew Monopole" <ma*******@hotmail.com> wrote in message
news:ht*****************@newsread2.prod.itd.earthl ink.net...
Since in integer we can use either
a = -b
and
a = b - c
shouldn't it when we overload operator there'd be two way to overload the
minus operator?
Yes, one is the unary version, the other is the binary version.
if so, what's the prototypes?
class operator-()
and
class operator-(class)?
Usually, you would pass const references to the operators and return
either a reference or a new object (depending on the operator). So for the
operator-, you would have the following:
myclass operator- ();
myclass operator- (myclass const& rhs);
This is pretty much what you said already. Now if you wanted to overload
operator-= as well, it would looke like this:
myclass& operator-= (myclass const& rhs);
Note that now you return a reference, because you do modify the current
object, instead of creating a new one.
hth
--
jb
(replace y with x if you want to reply by e-mail)