Hi guys I read something about destructor and I wonder if it is only needed when pointer member existed in certain member ? it seemed useless to delete something like int or char when our class instances are gone. :)
thanx in advance~
Printable View
Hi guys I read something about destructor and I wonder if it is only needed when pointer member existed in certain member ? it seemed useless to delete something like int or char when our class instances are gone. :)
thanx in advance~
it is mostly used when you have allocated dynamic memory,because if you allocate dynamic memory it will not be deleted automatically even class instances are destroyed(out of scope).
you have to explicitly delete that memoery in a destructor....
Classes with virtual functions should also have a virtual destructor, even if it does nothing.(faq) Also remember the rule of three if you need to write your own dtor, copy ctor, or assignment operator, you generally need to write all three.