Search code examples
c++inheritanceconstructordefault-constructor

What constructor activate first, the class objects or the class parent?


For example:

Class A
{
  A();
}

Class B
{
  A a;
  B(A& m_a) : a(m_a)
}

Which constructor will apply first? the A() constructor of the B parent, or the A object inside class B?


Solution

  • If you are asking the order of the parent and derived class constructors, see Are parent class constructors called before initializing variables?.

    In short, the base (or parent) class (looks like A in your case) constructor will complete first.