0Pricing
C++ Academy · Lesson

Single and Multiple Inheritance

Model is-a relationships with single inheritance and tame multiple inheritance pitfalls.

What is Inheritance?

Inheritance lets one class (the derived class) reuse and extend another (the base class). It models "is-a" relationships.

class Animal {
public:
    void breathe() { std::cout << "breathing\n"; }
};

class Dog : public Animal {
public:
    void bark() { std::cout << "Woof!\n"; }
};

Public Inheritance

Use public to model "is-a" — a Dog is an Animal. Members keep their access level in the derived class.

All lessons in this course

  1. Single and Multiple Inheritance
  2. Virtual Functions and the vtable
  3. Abstract Classes and Pure Virtual Methods
  4. Inheritance vs Composition Trade-offs
← Back to C++ Academy