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
- Single and Multiple Inheritance
- Virtual Functions and the vtable
- Abstract Classes and Pure Virtual Methods
- Inheritance vs Composition Trade-offs