Module lessons (1/2)
Inheritance in C++
Create class hierarchies with public inheritance, understand the protected specifier, and invoke base class constructors.
What you'll learn in this lesson
- Create class hierarchies with
: public Baseinheritance by expressing is-a relationships. - Distinguish visibility of
privatevsprotectedin derived classes. - Delegate arguments to the base class constructor via
: Base(args)and know the constructor/destructor order.
Overview
Inheritance allows a derived class (Car) to inherit members and public contract from a base class (Vehicle). In C++ the standard form of public inheritance is written : public Base.
Without : public, a class Derived : Base would use private inheritance by default hiding the base methods from the outside world! Therefore always specify : public:
Sections covered in this lesson
- 11. Inheritance
: publicand Accessibilityprotected - 22. Base Class Initialization and Construction/Destruction Order
- 33. Inheritance vs Composition (
has-a) - 44. Delegation to the Base Builder +
using - 5Practical exercises
- 6Check for understanding
Unlock "Inheritance in C++" and the full Course C++ curriculum
Create class hierarchies with public inheritance, understand the protected specifier, and invoke base class constructors.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course C++ plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.