... 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.