+ 1

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??

22nd Oct 2019, 7:09 AM
Malem Yengkhom
Malem Yengkhom - avatar
1 Odpowiedź
+ 1
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.
22nd Oct 2019, 9:21 AM
HonFu
HonFu - avatar