Re: Why use new?
On 26 mar, 20:41, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
saneman wrote:
[..]
Ok I am a bit confused if I need to implement a destructor.
Most likely not. Read about "the Rule of Three".
Since I don't use new in the class Bob is it enough to just
do:
delete(b2);
Parentheses are superfluous.
as the last thing in the main function? Can't see what good any
destructor would do since it cannot destruct itself.
Presence of the destructor and the need to free the memory are
orthogonal.
So you're using the Boehm collector too:-).
Seriously, I think your statement can easily be misinterpreted.
One major reason to provide a user defined destructor is to free
memory. Memory allocated and managed within the class, though,
not the basic memory in which the class itself resides. (Which
I'm sure is what you meant.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34