From 5191203673309844735
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8466591b9cd11017
X-Google-Attributes: gidf78e5,public
From: Hyman Rosen <hymie@prolifics.com>
Subject: Re: C++ 'philosophy' question, Constructors/Destructors
Date: 2000/06/17
Message-ID: <t7aegl1s9q.fsf@calumny.jyacc.com>#1/1
X-Deja-AN: 635408077
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <394a5536.29331042@news.columbia.edu>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 961175618 mail2news:19982 mail2news mail2news.demon.co.uk
Organization: PANIX Public Access Internet and UNIX, NYC
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
User-Agent: Gnus/5.0806 (Gnus v5.8.6) Emacs/20.6
Mime-Version: 1.0
NNTP-Posting-Date: 16 Jun 2000 16:53:16 GMT
Newsgroups: comp.std.c++

lp178@columbia.edu (Leonid Portnoy) writes:
>     What is the reason C++ automatically calls the destructor for the
> base class after calling the destructor for the derived class? 

Because the whole object is being destroyed. The derived class destructor
cleans up in the derived part of the object, and the base class destructor
cleans up in the base part of the object.

>      Of course, I can set data=NULL, set flags, etc.. to prevent the
> base class's destructor from doing damage, but this seems like an
> inelegant solution.

If the designer of the base class did not have in mind that it could
be extended in the way you would like, then you may be out of luck.

>      This raises another question : Why does a class have only one
> destructor, but multiple constructors?

Because objects are created by intention, with expressions that
supply arguments that can be used to select a constructor. They
are destroyed without any such information, such as by going out
of scope, so there is only one destructor. You are perfectly free
to write multiple overloaded "destroy" functions and call them
yourself as needed.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




