🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Why allow virtual function calls in constructors?

#2301
From: Geoff Keating 9205156
Date: Wed, 25 Oct 1995 17:32
23 lines
1484 bytes
The draft WP says that [section class.cdtor:3]

  When  a  virtual function is called directly or indirectly from a con-
  structor (including from its ctor-initializer) or from  a  destructor,
  and the object to which the call applies is the object under construc-
  tion or destruction, the function called is the  one  defined  in  the
  constructor  or destructor's own class or in one of its bases, but not
  a function overriding it in a class derived from  the  constructor  or
  destructor's  class, or overriding it in one of the other base classes
  of the complete object (_intro.object_).

Why allow this, rather than refusing calls to virtual functions at
all? It would be nice to say that `if I override this function, then
the old version will _never_ be called on objects of this type'.

--
-Geoff Keating (keagchon@mehta.anu.edu.au)

---
[ 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: <46kuqc$j45@manuel.anu.edu.au>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: keagchon@mehta.anu.edu.au (Geoff Keating 9205156)
Newsgroups: comp.std.c++
Subject: Why allow virtual function calls in constructors?
Date: 25 Oct 1995 17:32:24 GMT
Organization: Australian National University
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <46kuqc$j45@manuel.anu.edu.au>
NNTP-Posting-Host: physics2.berkeley.edu