help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: destructor


From: Paul Pluzhnikov
Subject: Re: destructor
Date: Tue, 31 Jul 2007 21:33:24 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

STEVEN MARX <smarx@verizon.net> writes:

> I have an array as a class member which is constructed, using new, in a 
> constructor.

If it really is an array, e.g.

  struct Foo {
     int array[5];
  };

then you can't be using new on it. Likely you have not an array,
but a pointer to an array. Or maybe you have an array of pointers. Or
a pointer to an array of pointers.

Post (reduced) actual code, so we don't have to guess.

> The members of the array are pointers to a some class. Should i
> (must i) create a destructor to explicitly
> delete [] or can i rely on the compiler to take care of this
> thank you.

If you new anything in the constructor, then you *must* take care
of that memory in the destructor.

In addition, you must ensure that either the instance can't be
copied, or that it is copied correctly. See "Effective C++", Item 11.

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]