Chapter 6: Inheritance and Polymorphism

This chapter introduces the concepts and shows some examples of how to define inheritance relationships between C++ classes. Overriding methods, the virtual keyword, and simple examples show how polymorphism works.

6.1 Simple Derivation

Inheritance is a particular way to organize classes that is supported by all object-oriented languages. It enables classes to share code in many different ways and to exploit natural relationships between classes. It can also make well-designed classes more reusable.

To employ inheritance, you place the common features of a set of related classes together in a base class and then derive other, more specialized classes from it. Each derived class inherits all the members ...

Get Introduction to Design Patterns in C++ with Qt, 2nd Edition 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.