Why destructor is used in the class??

As per I know destructor is used to destroy the object. But I didn't get it completely. Can someone explain destructor elaborately??

10/22/2019 7:09:50 AM

Malem Yengkhom

1 Answer

New Answer


Any instance you create, will be destroyed when it stops to be valid. (For example, the function call, in which it was declared, ends.) By defining a destructor by hand, you can say what exactly is supposed to happen when an instance is destroyed. Sometimes that's important, for example when the instance requires memory manually, or opens a file or something like that.