Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 06:27 PM
Dave Theese
Guest
 
Posts: n/a
Default Unary + / -


Am I correct in saying that it is not possible to overload unary + and
unary -?


  #2  
Old July 19th, 2005, 06:27 PM
Oliver S.
Guest
 
Posts: n/a
Default Re: Unary + / -

> Am I correct in saying that it is not possible to overload[color=blue]
> unary + and unary -?[/color]

You're not. The following unary operators are overloadable:
! Logical NOT
& Address-of
~ One's complement
* Pointer dereference
+ Unary plus
++ Increment
– Unary negation
–– Decrement
And all of them are overloadable through a global function as
well as a non-static member-function (btw: the only operators
that are only overloadable as non-static members are =, ->, []
and ()).
  #3  
Old July 19th, 2005, 06:28 PM
Shane Beasley
Guest
 
Posts: n/a
Default Re: Unary + / -

"Dave Theese" <cheeser_1998@yahoo.com> wrote in message news:<iTv8b.1611$v%5.257@fed1read02>...
[color=blue]
> Am I correct in saying that it is not possible to overload unary + and
> unary -?[/color]

No.

class S {
public:
S (int value = 0) : myValue(value) { }
S operator+ () const { return -myValue; }
S operator- () const { return myValue; }

private:
int myValue;
};

int main () {
S x;
x = +x;
x = -x;
}

- Shane
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles