Chapter 13: Object-Oriented Programming: Polymorphism
-
13.3.1 Invoking Base-Class Functions from Derived-Class Objects
-
13.3.2 Aiming Derived-Class Pointers at Base-Class Objects - Error
-
13.3.3 Derived-Class Member-Function Calls via Base-Class Pointers - Error
-
13.3.4 Virtual Functions
- 13.5 Pure virtual Functions and Abstract Classes
- Employee.h
- L.24 "virtual double earnings const =
0" declares earnings() as a pure virtual function.
- Employee.cpp
- In this file, no implementation is provided for pure virtual
function earnings.
- L.53 provides the implementation of the virtual function
print().
- SalariedEmployee.h
- L.18 Declare a virtual function earnings().
- L.19 Declare a virtual function print().
- SalariedEmployee.cpp
- L.41 Don't forget this scope resolution operator. Otherwise
you will get recursive function calls.
- CommissionEmployee.h
- L.8 Class CommissionEmployee derives from Employee.
- L.21 Declare earnings() as a virtual function.
- L.22 Declare print() as a virtual function.
- CommissionEmployee.cpp
- L.10 The constructor passes the first name, last name and
social security number to the Employee constructor.
- L.56 Fucntion print() calls base-class function print() to
display the Employee-specific information.
- BasePlusCommissionEmployee.h
- Same as Fig. 13.5
-
BasePlusCommissionEmployee.cpp
- Same as Fig. 12.15
- fig13_17.cpp
- L.62 A reference to the object is obtained by dereferencing
the pointer.
- L.77 Each call to virtualViaReference invokes virtual
function earnings via reference baseClassRef to demonstrate
polymorphism.
- 13.8 Rumtime Type Information