C++ ClassesLesson 38Free preview
C++ Inheritance
This lesson is part of C++ · All levels
Summary
Inheritance makes a new class (derived) able to reuse another class (base) so that code is not duplicated. The derivative class automatically gets the public method and data/protected from its parent, and can add features or replace them itself. C++ supports single, multiple, multilevel, as well as protected and private inheritance with different access rules.
Key points
- Basic syntax: class derived: public base {...}.
- In class, inheritance without modifier is private; in struct it is public.
- The constructor base is executed automatically before the constructor derives.
- Multiple inheritance allows one class to inherit from more than one base.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.