Topic: Virtual calls in constructors does not


Author: Stephen.Clamage@Eng.Sun.COM (Steve Clamage)
Date: 1997/04/14
Raw View
In article 5315@ix.netcom.com, "Paul D. DeRocco" <strip_these_words_pderocco@ix.netcom.com> writes:
>Paul Black wrote:
>>
>> The actual method called in the constructor is the one in the most derived
>> class that is no more "derived" than the class being constructed.
>> This means that the method is either in the current class or one of the
>> base classes (see draft section 12.7). The behaviour you posted is correct.
>
>Doesn't this represent a change from the past?

No.

Here's a quote from the draft standard, section 12.7 "Construction and
destruction":

"Member functions, including virtual functions (10.3), can be called during
construction or destruction (12.6.2). When a virtual function is called
directly or indirectly from a constructor (including from the mem-
initializer for a data member) or from a destructor, and the object to which
the call applies is the object under construction 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 most derived object (1.7)."

The ARM, in 12.7 page 294, says the same thing. There has been no change
in C++ in this regard.

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]