Exercises

  1. 11.3 (Composition as an Alternative to Inheritance) Many programs written with inheritance can be written with composition instead, and vice versa. Rewrite class BasePlusCommissionEmployee of the CommissionEmployeeBasePlusCommissionEmployee hierarchy to use composition rather than inheritance. After you do this, assess the relative merits of the two approaches for designing classes CommissionEmployee and BasePlusCommissionEmployee, as well as for object-oriented programs in general. Which approach is more natural? Why?

  2. 11.4 (Inheritance Advantage) Discuss the ways in which inheritance saves time during program development and helps prevent errors.

  3. 11.5 (Protected vs. Private Base Classes) Some programmers prefer not to use ...

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.