Order of calling constructors/destructors in inheritance

  • Construction always starts with the base class. If there are multiple base classes then, construction starts with the left most base. (side note: If there is a virtual inheritance then it’s given higher preference).
  • Then the member fields are constructed. They are initialized in the
    order they are declared
  • Finally, the class itself is constructed
  • The order of the destructor is exactly the reverse

Irrespective of the initializer list, the call order will be like this:

  1. Base class A‘s constructor
  2. class B‘s field named a (of type class A) will be constructed
  3. Derived class B‘s constructor

Leave a Comment