Hi,
I have a question. For arrays allocated with new I was taught to delete them
like:
delete [] array;
When the following is done, does it merely delete the "pointer" or does it also
delete the array:
delete array;
?
Or, if more appropriate, where can I look for more information?
TIA,
mike
holotko <[EMAIL PROTECTED]> wrote:
>
> Being spoiled by Java's garbage collector leads me to this quick
> question again concerning constructors in C++.
>
> If I allocate memory via "new" using a constructor
>
> i.e.
>
> class Foo
> {
> Foo()
> { word = new char[LENGTH + 1]; }
>
> ~Foo()
> { delete word; }
>
> ...
> }
>
> When I create an object of class Foo memory will be allocated for the
> char buffer "word". Now when the object is no longer needed must I
> make an explicit call to the destructor ~Foo() to destroy the object
> and subsequently call "delete", or, is the destructor somehow called
> automatically when the object is no longer needed,i.e. outside of
> it's scope?
>
> Even in Java there are times when it is up to you to destroy an object
> and/or free memory used for that object, depending on how the object
> is/was created and an method equivalent of a destructor is required...
> The garbage collector is not always adequate.
>
> Thanks...
>
> Sincerely,
>
> /John <[EMAIL PROTECTED]>
>
>
> --
> email: [EMAIL PROTECTED]
> Local mailserver <landreau.ruffe.edu> , remote <ns.computer.net>
>
> There is a great alternative to war, it's called Peace.