Declaring Inheritance

Up until this lesson, you have been using C++ as an object-based language. To be truly object-oriented, a language must be able to support inheritance.

Inheritance is the ability to create a new class whose capabilities are based on at least one other class (often called the superclass or ancestor). Inheritance has been called “programming by difference,” because the only code in the new class (called the derived class or descendant) is that which differs from the superclass.

Inheritance allows you to replace or add member functions or to add member variables to an existing class by creating a derived class and putting the changes in the new class. In most cases, you can do this without modifying the superclass.

You will ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND 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.