29.5 Overloading the ( ) Operator

I l @ ve RuBoard

The ( ) operator can be overloaded for a class to give the class a "default" function. For example:

 class example {     public:         int operator (  ) (int i) {             return (i * 2);         } }; // ....      example example_var;      j = example_var(3);    // j is assigned the value 6 (3 * 2) 

Overloading the ( ) operator is rarely done. Normal member functions can easily be used for the same purpose but have the advantage of providing the user with a function name .

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

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