0

In C++, execution of constructor and destructor while inheritance ?

I have a doubt on execution of constructor and destructor in c++... Like which executes 1st when two or more classes get inherited?

15th Apr 2018, 1:32 PM
ARIF ANSARI
ARIF ANSARI - avatar
3 Respostas
+ 4
I suppose you mean: What is the order of constructor calling when a derived class inherits characteristics or properties from a base class. In such a case, the constructor of the base class is executed first, followed by the execution of the derived class' constructor when an object of class derive ( i.e. the derived class ) is declared in the main() function. For order of destructor execution, it's the other way round. The destructor of the derived class is executed first, followed by the execution of the base class' destructor when the scope of an object of class derive ends. Hope your doubt got cleared. Happy coding!! edit: I did mention it ARIF ANSARI
15th Apr 2018, 1:55 PM
Rahul George
Rahul George - avatar
+ 2
Ok got it.. But what about deatructor, i mean the order of execution of destructor... Btw Thanks Rahul George
15th Apr 2018, 1:59 PM
ARIF ANSARI
ARIF ANSARI - avatar
+ 2
Thanks for helping Rahul George
15th Apr 2018, 2:06 PM
ARIF ANSARI
ARIF ANSARI - avatar