Joseph Keen wrote:

> > > In C++ you must always specifically call the destructor before the
> > > variable goes out of scope.
> > 
> > Wrong. The destructor will be called automatically when the variable
> > ceases to exist (i.e. upon leaving the enclosing function for
> > automatic variables, upon delete for dynamic variables, and upon
> > program termination for static variables).
> 
> Yes, once the delete routine is used the memory is freed but in the code
> sample he gave the delete call was enclosed in the destructor for the
> class.

Yes. But this has nothing to do with whether or not you have to call
the destructor yourself (you never do).

> Since from the code he wasn't using delete anywhere else he had to
> call the destructor implicitly.

The compiler will arrange for the destructor to be called at the
appropriate point.

> Not doing so would kill the variable but not free the memory used by
> the variable.

If the variable is destroyed (by delete, leaving scope, or program
termination), the destructor will be called automatically.

> There is the chance that it
> will be allocated to another variable along the line but it's always
> better to make sure you kill the variable yourself or else you risk losing
> some of your available memory.

What's your point? The additional memory which was allocated by the
constructor is deallocated by the destructor. Consequently, the
additional memory is used for exactly the lifetime of the variable
itself.

The original question was:

> Now when the object is no longer needed must I make an explicit call
> to the destructor ~Foo() to destroy the object

to which the answer is `no'.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to