Understanding inherited constructors and destructors
Through single inheritance, we can build a hierarchy of related classes. We have seen that when we instantiate a derived class object, memory for its base class data members is then followed by the additional memory required for the additional derived class data members. Each of these subobjects will need to be constructed. Luckily, each class will have defined a suite of constructors for just that purpose. We then need to understand how the language can be utilized to allow us to specify the appropriate base class constructor for the base class subobject when instantiating and constructing a derived class object.
Similarly, when an object of a derived class type is no longer needed and will be destructed, it is important to note that a destructor for each subobject comprising the derived class instance will be implicitly called on our behalf.
Let’s take a look at the constructor and destructor sequence in a single...