Article View: comp.std.c++
Article #2402Re: Why allow virtual function calls in constr
From: kanze
Date: Thu, 02 Nov 1995 23:19
Date: Thu, 02 Nov 1995 23:19
49 lines
3198 bytes
3198 bytes
In article <1995Oct31.171443.3987@oma.com> rmartin@oma.com (Robert
Martin) writes:
|> harald@bion.kth.se (Harald Winroth) writes:
|> >There is a common pattern in which a base class implements an algorithm but
|> >leaves some of the steps unspecified (in C++ typically as pure virtual
|> >functions). These steps are later defined in subclasses. The current
|> >standard draft prevents this pattern to be used in constructors, which I
|> >think is unfortunate.
|> I agree that the current rules for deploying virtual functions in
|> constructors and destructors can be inconvenient at times. But they
|> have a distinct advantage. The rules, written as they are, guarantee
|> that no member function of a class (other than one of its
|> constructors) will be called until all the members and bases of that
|> class have been initialized.
Actually, the rules make this guarantee even for constructors and
destructors. The only code in class X that can be executed before all
of the subobjects are initialized is the initialization lists of
constructors; off hand, I don't believe that (non-static) member
functions can be called in initialization lists. (I'm too lazy to
check, and since it isn't something I'd want to do anyway.)
IMHO, this is a *very* important guarantee, well worth the occasional
inconvenience.
|> If the rules allowed virtual deployment in constructors or
|> destructors, then functions could be called in classes where the
|> members and/or bases had not been initialized, or had been destructed.
|> And this, IMHO, would be untennable.
Also, these functions would presumably not have anyway of knowing that
the subobjects were only raw memory. So they would probably use
functions of the subobjects, with the result that everyday member
functions end up getting called on raw memory. Not exactly what I
would call a healthy state of affairs.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9511021143.AA01851@slsv7xt.lts.sel.alcatel.de>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<46kuqc$j45@manuel.anu.edu.au> <46mgqo$e5b@engnews2.Eng.Sun.COM> <9530301.15557@mulga.cs.mu.OZ.AU> <470gvp$i3h@engnews1.eng.sun.com> <HARALD.95Oct30103929@moon.bion.kth.se> <1995Oct31.171443.3987@oma.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 02 Nov 95 23:19:50 GMT Approved: fjh@cs.mu.oz.au Organization: - X-Original-Date: Thu, 2 Nov 95 12:43:34 +0100 From: kanze <kanze@lts.sel.alcatel.de> Message-ID: <9511021143.AA01851@slsv7xt.lts.sel.alcatel.de> In-Reply-To: rmartin@oma.com's message of 31 Oct 95 16:37:11 GMT Newsgroups: comp.std.c++ Subject: Re: Why allow virtual function calls in constr References: <46kuqc$j45@manuel.anu.edu.au> <46mgqo$e5b@engnews2.Eng.Sun.COM> <9530301.15557@mulga.cs.mu.OZ.AU> <470gvp$i3h@engnews1.eng.sun.com> <HARALD.95Oct30103929@moon.bion.kth.se> <1995Oct31.171443.3987@oma.com> X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMJlSIeEDnX0m9pzZAQGVqgGAmoKWnYVAvQzryxLxQbnUNPTNj5Aw5V8g QFfi4Hpwc4cpVOABAPhDHbGKC2O1PflD =hMmX