+ 1
How destructor works while object is deleted??
3 ответов
+ 3
when you delete an object that was created in the heap, or when an object define as a local variable gets out of scope, the destructor is called.
if your object is complex, specifically, if its class has members allocated in the heap with new, the destructor code should clean (delete) those members up as to not leave memory leaks.
+ 1
c++
+ 1
Rikki when the scope of object is over , destructor is automatically gets called by compiler...
in same scope for more than one objects, it's order to get destroyed is reverse than object creation order..
for example, if you have created obj1 first and obj2 last, at the end of main function; first obj2 will be destroyed by destructor and then obj1...