View Single Post
  #2 (permalink)  
Old 05-13-2008, 06:39 AM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 111
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
Yes, that will work since operator overloading allows the same flexibility as overloading a function. (confined within the usual 'rules' of those operators of course)

You can also change an operator's behaviour dependent on the type of the either operand, externally from a class.
Code:
class foo
{
public:
   friend float operator+ (float, const foo&);
   friend float operator+ (int, const foo&);
};

float operator+ (float, const foo&);
float operator+ (int, const foo&);

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Bench : 05-13-2008 at 06:45 AM.
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
MrPickle (05-13-2008)