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~
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~
Never end on learning~
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....
Two men looked out from Prison Bars,One saw the mud,the other saw stars.
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.