Actually the destructor should be
      ~Foo()
        { delete[] word; } // as an array has been allocated.

vive,
Prasanna subash


>Hi,
>The destructor is automatically called when the
>object in question is no longer needed. Such as
>an object is created inside a function locally and
>when the function returns the object gets killed with
>the destructor executed. Hence we dont call the 
>destructor explicitly.
>
>And in java I feel the garbage collection concept is
>implemented quite strong and rarely do we use explicit
>deallocation.
>
>Cheers,
>Suresh 
>Wipro-Nortel Networks
>Bangalore
>>
>>
>>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.
>>
>
>
>--


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Reply via email to