In this article I’m going to introduce how to perform object inheritance in C++. When we use inheritance in our C++ programs, we are modeling is-a relationships. For example, a dog is-a mammal; a Volkswagen Beetle is-a car; a square is-a shape. This means, to use the Volkswagen Beetle as an example, that the Beetle has many of the attributes of the typical car, though it may have some attributes that other cars don’t have, and the attributes it shares with cars may not be identical to other cars. The shape of a Beetle, for example, is completely different than any other car shape. But in general, an object that inherits from another objects will have many features in common with the object it inherits from.

Some Terminology

The class we are going to inherit from is called the base class. The class that is inheriting from another class is called the derived class. A set of classes that include a base class and one or more derived classes is called a class hierarchy. When a derived class inherits from just one base class, that is known as single inheritance. When a derived class inherits from more than one class, that is called multiple inheritance. I will be working with single inheritance in this set of articles.

#learning-to-program #object-oriented #oop-concepts #cpp #c++

Learning C++: Inheritance
1.15 GEEK