+ 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
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.
0
yes your right great job
0
Imo it may be risky to say that. If you want a fixed and known order of destruction you should use delete keyword.