- 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 14:
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 15:
Employee class header file.
|
Figure 16:
Employee class implementation file. (part 1 of 2)
|
Figure 17:
Employee class implementation file (part 2 of 2) and SalariedEmployee class
header file.
|
Figure 18:
SalariedEmployee class implementation file.
|
Figure 19:
HourlyEmployee class header file.
|
Figure 20:
HourlyEmployee class implementation file.
|
Figure 21:
CommissionEmployee class header file.
|
Figure 22:
CommissionEmployee class implementation file.
|
Figure 23:
BasePlusCommissionEmployee class header file.
|
Figure 24:
BasePlusCommissionEmployee class implementation file.
|
Figure 25:
Employee class hierarchy driver program.(part 1 of 2)
|
Figure 26:
Employee class hierarchy driver program.(part 2 of 2)
|
2004-07-29