Path: utzoo!attcan!uunet!comp.vuw.ac.nz!actrix!Bruce.Hoult From: Bruce.Hoult@actrix.co.nz (Bruce Hoult) Newsgroups: comp.lang.c++ Subject: Re: conditional scope and destructors Message-ID: <1990Nov10.182930.2772@actrix.co.nz> Date: 10 Nov 90 18:29:30 GMT References: <1990Nov9.151803.11426@hemel.bull.co.uk> Organization: Actrix Public Access UNIX, Wellington, New Zealand Lines: 13 Comment-To: pmoore@hemel.bull.co.uk >If foo does equal bar then obj is not created - should its destructor >be called when the return is done? Zortech 2.1 does call it. It is probably bad form to put a return statement other than at the end of the function -- especially for maintenance reasons. You could put the rest of the function body in an "else" clause, or even just in {} to create a new scope. Because the object was declared in the function scope (rather than in some enclosed scope within the function) it actually exists for the entire execution of the function. The error is not the compiler calling the destructor, but your failure to ensure that it is correctly constructed in all possible execution paths.