C++ Inheritance: Order of Execution of ConstructorsWhenever an object of a derived class is created, its base class constructor is executed before the execution of the derived class constructor. Objects of derived class and base class are destroyed in the reverse order: first the object of derived class, then the object of base class. If a class’ data member is an object of another class, then, the constructor of the member object is invoked before that of its enclosing class. For instance:class BM { // . . .}; class DM { // . . .}; The relationships among the above classes can be represented graphically using the Unified Modeling Language (UML):
The execution order of constructors is (bottom-up) BM, Base, DM, and Derived.And the execution order of destructors is (top-down) Derived, DM, Base, BM. |