From 7369104274472981303
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8466591b9cd11017
X-Google-Attributes: gidf78e5,public
From: comeau@panix.com (Greg Comeau)
Subject: Re: C++ 'philosophy' question, Constructors/Destructors
Date: 2000/06/17
Message-ID: <8ie1dm$qtj$1@panix6.panix.com>#1/1
X-Deja-AN: 635478618
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <394a5536.29331042@news.columbia.edu> <t7aegl1s9q.fsf@calumny.jyacc.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 961187090 mail2news:27913 mail2news mail2news.demon.co.uk
Organization: Comeau Computing; http://www.comeaucomputing.com
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Reply-To: comeau@comeaucomputing.com
Newsgroups: comp.std.c++

In article <t7aegl1s9q.fsf@calumny.jyacc.com>,
Hyman Rosen  <hymie@prolifics.com> wrote:
>lp178@columbia.edu (Leonid Portnoy) writes:
>>      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.

I'm not clear this is what you just said, but it's worth pointing out
that destruction is not quite the reverse of construction, despite
so many people being told it is.  That is to say, yes, while
ctors turn raw memory into something useful and dtors turn those
useful thing back ("reverse") to raw memory, what's also important
to note is that you need to consider the life of the object.
Once the object is "alive", what happened at construction time
may or may not be important anymore, therefore, have a matching
dtor may or may not be important anymore.  This sort of begs that
if it has multiple ctors then it should be a requirement that there
be multiple versions of every member function, not just dtors....
which does not necessarily follow... clearly it may in certain cases,
but apparently they were not deemed common/significant enough, and
when they are, you do somethign such as what Hyman suggests.

- Greg
-- 
Comeau Computing, Producers of Comeau C/C++ 4.2.42 (4.2.43 BETA starting)
Try Comeau C++ online at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com

---
[ 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              ]




