335 views
1 votes
1 votes
How is the order of invocation of destructors different from constructors?

1 Answer

Best answer
3 votes
3 votes

Order of Constructor Invocation is Base Class then Derived Class

While order of Destructor Invocation is Derived Class and then Base Class

However, this can be understood diagrammatically as below:

A Derived class is a specialization of a Base Class. This is means some features are added or modified in the specialized (Derived) class.

  • To construct above diagram, I would first construct inner box (base class) and then construct outer box (derived class). That is why Base class constructor is invoked before the derived class constructor
  • And when I have to erase (destruct) the diagram, I will first erase the outer box (derived class) and then erase the inner box (base class). That is why Derived class destructor is invoked before base class destructor
selected by

Related questions

0 votes
0 votes
1 answer
1
iarnav asked May 27, 2017
237 views
What is meant by object slicing?
0 votes
0 votes
2 answers
2
iarnav asked May 27, 2017
481 views
What is meant by precedence rule for evaluation of expressions?
0 votes
0 votes
1 answer
3
iarnav asked May 27, 2017
244 views
What are structured languages and what are their major features?
0 votes
0 votes
1 answer
4
iarnav asked May 27, 2017
269 views
Consider a pointer declaration int i=10,*p; p=&x;Is p – – ; a valid statement, justify? explain in as simple way as possible.