Previous      Up      Previous     Course Home   e-mail

1.1 Operators are Functions

Operators are Functions   


Examples: operators as functions   


Declaring Operators   

Understanding that shorthand, we can declare our own operators by giving the appropriate operator function name:

class BidCollection {
          
  void addInTimeOrder (const Bid& value);
  //  Adds this bid into a position such that 
  //   all bids are ordered by the time the bid was placed
  //Pre: getSize() <</span> getMaxSize()

  void operator+= (const Bid& value)  
           {addInTimeOrder(value);}
          
Then

bids . addInTimeOrder ( b ) ;
and

bids += b ;
would do the same thing

Keep it Natural   


Most Commonly Overloaded Operators   

There are, however, 3 groups of operators that are very commonly overloaded


 Previous      Up      Previous     Course Home   e-mail