Topic: Virtual calls on unfinished objects (was: Why allow virtual...)


Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1995/10/31
Raw View
>>>>> "SC" == Steve Clamage <clamage@Eng.Sun.COM> writes:

Thanks for your clarification; I (wrongly) remembered that virtual calls
in the constructor used to be prohibited.

SC> In article 95Oct29144834@avs.cs.rpi.edu, vandevod@cs.rpi.edu
SC> (David Vandevoorde) writes:
[...]
SC> I think you would have to add this feature, or else disallow
SC> virtual calls from constructors and destructors.
>>  Right now, I think it makes sense disallowing them.

SC> The problem is actually a little more subtle. You also have to
SC> disallow passing the value of "this" out of a constructor or
SC> destructor, or make the results of doing so undefined. A
SC> constructor (destructor) for T might call an ordinary global
SC> function which takes a pointer to T and calls a virtual function.

Or perhaps more generally: virtual calls on incompletely constructed
objects are undefined. Hence the this-pointer could be exported by
the constructor for storage purposes (and potential call after
construction is finished). Would that do?

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