From: sparhawk AT eunet DOT at (Gerhard Gruber) Newsgroups: comp.os.msdos.djgpp Subject: Re: Deconstructors Date: Sat, 18 Jul 1998 09:28:44 GMT Organization: Customer of EUnet Austria Lines: 72 Message-ID: <35b6691c.3375145@news.Austria.EU.net> References: <35AFE02F DOT 3C4857ED AT logic-gate DOT com> <35AFEF99 DOT 29955266 AT alcyone DOT com> NNTP-Posting-Host: e046.dynamic.vienna.at.eu.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Content-Transfer-Encoding: 8bit Precedence: bulk Destination: Erik Max Francis From: Gruber Gerhard Group: comp.os.msdos.djgpp Date: Fri, 17 Jul 1998 17:43:05 -0700: >Michael Tanczos wrote: > >> When are deconstructors called when using classes? At the >> end of the program if it's declared statically.. or when >> you delete the object if it's declared dynamically? Or do >> you need to call the deconstructor directly.. > >Automatic (local) objects are deconstructed when they go out of scope. Are you sure? Waht about code like this? main() { class c1; do something if(x) { class c2; } } Usually local variables are allocated by the compiler at the function entry regardless wether they are in subscope or not. Your above statement would mean that c1 is constructed at the entry of main (that's true) and deconstructed at the exit of main (also true). But c2 would be constructed afer entering the condition and deconstructed when leaving that condition. I'm nbot sure if this is true. I rather think that c2 is internally handled just like c1. >You should not be attempting to explicitly call a destructor unless you >are doing something very, very strange. That's why I usually write a function that resets the object and call this function when I need it and also from the destructor. i.e.: class x { public: x(); ~x(); Destroyx(); }; x:~x() { Destroyx(); } x:Destroyx() { reset object } -- Bye, Gerhard email: sparhawk AT eunet DOT at g DOT gruber AT sis DOT co DOT at Spelling corrections are appreciated.