12.1 OPERATOR TOKENS AND OPERATOR FUNCTIONS


12.1 OPERATOR TOKENS AND OPERATOR FUNCTIONS

You have seen many instances of the usual operator tokens in C++:

     +  -  *  /  =  ->&&  new  new[]  delete  delete[]  etc. 

When the arguments supplied to any of these and other operators are of class type, what the compiler actually invokes is an operator function that is associated with the operator token. For example, for the case of class type arguments, associated with the operator token ‘+’ is the following operator function

      operator+ 

Similarly, associated with the operator token, or operator for short, ‘=’ is the operator function

      operator= 

and with the operator ‘<<,’ the operator function

      operator<< 

Overload definitions for operator functions come in two forms: Definitions that are global and definitions that are member functions for a class. When it is possible to provide overload definitions both ways, the overloaded operator works the same with either implementation.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net