What's the use of explicitly defining a destructor?

Mar 31, 2013 at 11:24am
What's the use of explicitly defining a destructor? When an object goes out of scope, its default destructor is called and memory space referenced by the *this pointer is automatically deallocated, right? Then what's the need for explicitly defining a destructor?
Mar 31, 2013 at 11:29am
If your object has allocated its own memory, for example by using new, then the corresponding delete will go in the destructor.
Mar 31, 2013 at 3:02pm
closed account (zb0S216C)
Deallocating memory isn't the only reason why one should overload the default destructor. If your class needs to perform some specific task before it's destroyed, overloading the destructor will allow the object to do just that.

Wazzak
Topic archived. No new replies allowed.