Class Extension and Operator Overloading


Some of the functions in the base class may be operators and therefore it may be desirable to have the operators also work on the derived class as well. To illustrate this possibility, the example datereln.cpp was created. This program includes the header newdate.h.

One point should be observed with respect to this type of extension. When an operator is defined in the base class, the output of the operators may be objects of the base class. In order for such an operator to be extended to the derived class, an assignment operator or a type conversion from the base to the derived class may need to be defined. For example see: cmlxasgn.cpp

The operators: << and >> can not be inherited since they are friend functions and are not member functions. Therefore if they are needed in a derived class, they must be defined for the derived class as well.

In inheritance how can the operator ++() be extended when the base has the operator + and you want to base the operator ++() on the operator +. Next are listed two different solutions to this question. The last of which uses the this pointer: don.cpp and bubba.cpp




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

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