+ 1

What is destructor order of execution????

for example if i have 3 objects and i define a constructor and destructor so what is order destructor execution class test{ public: test(){ cout<<"this is constructor"; } ~test(){ cout<<"this is destructor"; }; int main(){ test obj1; test obj2; test obj3; } destructor will invoked when end of main block execution try it i know aswer i will share but not now

12th Mar 2017, 12:23 PM
Swamy Kanuri
Swamy Kanuri - avatar
3 odpowiedzi
0
I guess it's - obj3 ~ - obj2 ~ - obj1 ~ I'm not 100% sure, but I think the objects are somewhat stacked. And since obj3 is the last object to be instanciated, it should be the first one to geht destroyed.
12th Mar 2017, 1:28 PM
Hoargarth
Hoargarth - avatar
0
yes your right great job
12th Mar 2017, 1:34 PM
Swamy Kanuri
Swamy Kanuri - avatar
0
Imo it may be risky to say that. If you want a fixed and known order of destruction you should use delete keyword.
18th Mar 2017, 11:56 AM
Michał Wilczyński
Michał Wilczyński - avatar