Constructor Inheriting

In this lesson, we'll discuss how constructor calls are initiated when we call an object in the main section.

Constructor calls #

When we call a constructor, a series of constructor calls may be triggered. This guarantees that each base object is properly initialized. The sequence of constructor calls starts with the base class and ends with the most derived class.

Example #

Let’s check how the series of calls is initiated when an object is called:

struct A{};
struct B: A{};
struct C: B{};
C c;              // A -> B -> C

Inheriting base class constructors #

By using the declaration, a class inherits all constructors of its direct base class.

Only the default constructor is inherited, the copy and move constructor will not be inherited.

Get hands-on with 1200+ tech skills courses.