- Base class Employee
- Pure virtual function earnings (returns pay)
- Pure virtual because need to know employee type
- Cannot calculate for generic employee
- Other classes derive from Employee
Figure 5.26:
Class hierarchy for the polymorphic employee-payroll application.
|
- Downcasting
- dynamic_cast operator
- Determine object's type at runtime
- Returns 0 if not of proper type (cannot be cast)
- NewClass *ptr = dynamic_cast < NewClass *> objectPtr;
- Keyword typeid
- Header <typeinfo>
- Usage: typeid(object)
- Returns type_info object
- Has information about type of operand, including name
- typeid(object).name()
Figure 5.27:
Employee class header file.
|
Figure 5.28:
Employee class implementation file. (part 1 of 2)
|
Figure 5.29:
Employee class implementation file (part 2 of 2) and SalariedEmployee class
header file.
|
Figure 5.30:
SalariedEmployee class implementation file.
|
Figure 5.31:
HourlyEmployee class header file.
|
Figure 5.32:
HourlyEmployee class implementation file.
|
Figure 5.33:
CommissionEmployee class header file.
|
Figure 5.34:
CommissionEmployee class implementation file.
|
Figure 5.35:
BasePlusCommissionEmployee class header file.
|
Figure 5.36:
BasePlusCommissionEmployee class implementation file.
|
Figure 5.37:
Employee class hierarchy driver program.(part 1 of 2)
|
Figure 5.38:
Employee class hierarchy driver program.(part 2 of 2)
|
2004-12-28