Article View: comp.std.c++
Article #2307Re: Why allow virtual function calls in constructors?
From: David Sachs
Date: Thu, 26 Oct 1995 02:43
Date: Thu, 26 Oct 1995 02:43
33 lines
2368 bytes
2368 bytes
keagchon@mehta.anu.edu.au (Geoff Keating 9205156) writes: >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'. In general the compiler CANNOT diagnose a call to a virtual function from a constructor or destructor - the call might very well come from a non-virtual function in a separate compilation unit. In view of this, the specification in the standard that the virtual function call be treated as if the actual object were of the type of the constructor or desctructor currently being executed is certainly within reason. -- ** The Klingons' favorite food was named by the first earthling to see it ** David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510 Voice: 1 708 840 3942 Deparment Fax: 1 708 840 3785 --- [ 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:
<46m5ki$shb@fsgm01.fnal.gov>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<46kuqc$j45@manuel.anu.edu.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 26 Oct 95 02:43:32 GMT Approved: fjh@cs.mu.oz.au From: b91926@fsgm01.fnal.gov (David Sachs) Newsgroups: comp.std.c++ Subject: Re: Why allow virtual function calls in constructors? X-Original-Date: 25 Oct 1995 15:10:58 -0500 Organization: FERMILAB, Batavia, IL Message-ID: <46m5ki$shb@fsgm01.fnal.gov> References: <46kuqc$j45@manuel.anu.edu.au> Reply-To: sachs@fnal.fnal.gov X-Newsreader: NN version 6.5.0 #4 (NOV) X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMI714OEDnX0m9pzZAQFYowF/fPirEAqpPk/A+Ih9Fk9xYgwWZA0H0Z3x UfK6/0SgGe7ISckGvV+WmvDmpAqfgIEG =eKpq