Skip to main content
GameDev.net gamedev.net
🔒 Locked

Overloading operators in C++

Started by LukeSkyRunner Mar 26, 2004 at 1:52 PM 3 replies 450+ views
Original Post
LukeSkyRunner
LukeSkyRunner
Which operators can I overload in C++? +, -, /, *, ==, !=, is there any other I did not write here?
Sneftel
Sneftel
All operators, with the exception of the dot operator, the dot-star operator, the scope resolution operator, the ternary operator, and the sizeof operator (yes, sizeof is technically an operator).


"Sneftel is correct, if rather vulgar." --Flarelocke
Palidine
Palidine
you can overload any operator.

you forgot, among others:

<<, >>, ++, --, +=, -=, *=, /=, probably more. why not just google the web and read a chapter on operator overloading?

-me
Agony
Agony
MSDN List of Overloadable Operators

Especially powerful ones could include (), [], new, and delete. Heck, you can even confuse everyone who looks at your code by overloading the comma operator and using it all the time. Not recommended, of course, but doable.


int Agony() { return *((int*)0); }    Mwahaha... >8)
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
mattnewport
mattnewport
You can also overload all of these operators:
!, %, ^, &, |, ~, <, >, &&, ||, ->, ->*, [], (), new, new[], delete, delete[] 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.