The Idea of Inheritance
Different things often have something in common. Buses and cars are all four-wheeled vehicles, a goat and a sheep are both plant-eating domesticated animals, and so on. In object-oriented programming things are modeled using classes; inheritance is a powerful way to express the common properties of classes.
Inheritance, as you will see, will also save you a lot of typing. A class can inherit all the properties of another class, plus some extra functionality. So it is useful for customizing existing classes.
Extending a struct
Say you want to define an Employee class. In Chapter 7 you created quite a lot of code that uses the Person class, and so it seems reasonable just to copy the fields of Person and add some extra fields ...
Get C++ By Example: UnderC Learning 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.