Derived class constructor

Can someone help me see why this apparent asymmetry make sense?


A derived class’s constructor explicitly invokes its base class’s constructor, but a derived class’s destructor cannot invoke its base class’s destructor.
But it does so, implicitly.

The derived class is first destructed, then its direct base(s).
The only value in explicitly calling the ctor is so that you can choose which ctor to call and/or pass parameters to it.

There is no overloading dtors and they can't have parameters, so there's no benefit or reason to explicitly call them.

Furthermore, objects are constructed "bottom up" and destructed "top down". The base class must be fully constructed before the derived class is constructed.... and the derived class must be fully destructed before the base class is destructed. Calling the base class dtor would destroy that system, which could be disasterous.
You never invoke destructors explicitly. Destructors are automatically invoked when a object goes out of scope or when a dynamically allocated object is deleted. Inheritance does not change this behavior. This is the reason a derived destructor cannot invoke its base class destructor. Compiler takes care of implicitly invoking the destructor for the base class.

In the case of a constructor, explicit base class constructor invocation is only required when the base class has a non-default constructor. If a base class has default constructor, there is no need to explicitly invoke the base class constructor.
Topic archived. No new replies allowed.