12.3.2. Aiming Derived-Class Pointers at Base-Class Objects
In Section 12.3.1, we assigned the address of a derived-class object to a base-class pointer and explained that the C++ compiler allows this assignment, because a derived-class object is a base-class object. We take the opposite approach in Fig. 12.2, as we aim a derived-class pointer at a base-class object. [Note: This program reuses the final versions of classes
BasePlusCommissionEmployee from Section 11.3.5.] Lines 8–9 of Fig. 12.2 create a
CommissionEmployee object, and line 10 creates a
BasePlusCommissionEmployee pointer. Line 14 attempts to assign the address of base-class object
commissionEmployee to derived-class pointer
basePlusCommissionEmployeePtr, but ...