🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2372

Re: Why allow virtual function calls in constr

#2372
From: Robert Martin
Date: Tue, 31 Oct 1995 16:37
28 lines
2178 bytes
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.

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.
-- 
Robert Martin       | Design Consulting   | Training courses offered:
Object Mentor Assoc.| rmartin@oma.com     |   OOA/D, C++, Advanced OO
2080 Cranbrook Rd.  | Tel: (708) 918-1004 |   Mgt. Overview of OOT
Green Oaks IL 60048 | Fax: (708) 918-1023 | Development Contracts.
---
[ 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: <1995Oct31.171443.3987@oma.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
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>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 31 Oct 95 16:37:11 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
From: rmartin@oma.com (Robert Martin)
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>
Organization: R. C. M. Consulting Inc. 708-918-1004
X-Original-Date: Tue, 31 Oct 1995 17:14:43 GMT
Message-ID: <1995Oct31.171443.3987@oma.com>
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMJZQwuEDnX0m9pzZAQHXXQGAhWrAkaICm/vQRM1szL8cXcjrWhFjmgSw
 Y17bGWy8qmDeDxQVJhdl8TX4ti7Q12LE
 =QDSI