InterviewSolution
| 1. |
If class D is derived from a base class B. When creating an object of type D in what order would the constructors of these classes get called? |
|
Answer» The derived CLASS has two parts, a base part, and a derived part. When C++ constructs derived objects, it does so in phases. First, the most-base class(at the top of the INHERITANCE TREE) is constructed. Then each child class is constructed in order until the most-child class is constructed last. During the destruction EXACTLY reverse order is followed. That is destructor starts at the most-derived class and works its way down to base class. |
|