0

When does the destructor called in the program?

destructor destroy the program.

15th Mar 2018, 6:33 PM
Tayyab arifeen
Tayyab arifeen - avatar
2 odpowiedzi
+ 22
we use it to destroy or delete an object https://www.sololearn.com/learn/CPlusPlus/1875/?ref=app
15th Mar 2018, 6:39 PM
Youssef Ouamou
Youssef Ouamou - avatar
+ 3
For C++, a destructor is called in 2 cases I can think of: 1. if you defined an object within a block, i.e. within a pair of {}, then it is deleted when it goes out of scope at the end of the brace. such object are allocated on the stack. 2. If you explicitly defined it by using the 'new' operator, it will get deleted when you explicitly call the 'delete' operator. Such objects are allocated off the heap.
15th Mar 2018, 6:41 PM
Udi Finkelstein
Udi Finkelstein - avatar