... function toString on the CommissionEmployee object. This invokes the version of toString defined in base class CommissionEmployee.

Aiming a Derived-Class Pointer at a Derived-Class Object

Similarly, lines 34–35 create basePlusCommissionEmployeePtr—a pointer to a BasePlusCommissionEmployee object—and initialize it with the address of derived-class object basePlusCommissionEmployee. Line 39 uses the pointer to invoke member function to-String on the BasePlusCommissionEmployee object. This invokes the version of to-String defined in derived class BasePlusCommissionEmployee.

Aiming a Base-Class Pointer at a Derived-Class Object

Line 42 then assigns the address of derived-class object basePlusCommissionEmployee to base-class pointer commissionEmployeePtr ...

Get C++ How to Program, 10/e now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.