From 3188096413690495068
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,3cdb654b702f7476
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2000-08-26 19:35:19 PST
Path: supernews.google.com!sn-xit-02!sn-east!supernews.com!newspeer.monmouth.com!newsfeed.icl.net!dispose.news.demon.net!demon!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: kanze@gabi-soft.de
Newsgroups: comp.std.c++
Subject: Re: virtual functions
Date: Sun, 27 Aug 2000 02:34:24 GMT
Organization: Customer of UUNET Deutschland GmbH
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <86vgwowaoq.fsf@gabi-soft.de>
References: <399A78E4.8345D7B@gmx.at> <m23dk5jiuq.fsf@brownie.frogger.foobar.snot> <399B8FA6.540D5B7F@gmx.at> <m2hf8jigxk.fsf@brownie.frogger.foobar.snot> <XfLn5.3006$Vb.76744@ozemail.com.au> <86itsr207l.fsf@gabi-soft.de> <QM5p5.389$cr3.13754@ozemail.com.au>
X-Trace: mail2news.demon.co.uk 967343673 mail2news:28926 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
User-Agent: Gnus/5.0805 (Gnus v5.8.5) Emacs/20.4
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mulga.cs.mu.OZ.AU id NAA06737
Lines: 50
Xref: supernews.google.com comp.std.c++:383

"michael" <serrano@ozemail.com.au> writes:

|>  > > > It is true only inside constructors *and* destructors. In all
|>  > > > other cases, the overriding method of the object's dynamic
|>  > > > type is called.

|>  > > It is true during construction and destruction.  You can't
|>  > > defeat the behaviour by having the ctor forward to a helper.

|>  > In all cases, the overriding method of the object's dynamic type
|>  > is called.  There are no special rules for constructors or
|>  > destructors.  (Of course, in the constructor or destructor for X,
|>  > the dynamic type of the object is X.)

|>  Yes, a fine unification.

|>  (but there _is_ a special rule:
|>  12.7/3&4 _define_ the dynamic type of the object during
|>  contruction/destruction in this special way.    Without this rule, I
|>  might think the dynamic type was the type used in the new expresion
|>  or declaration of the object.)

I wouldn't call it a "special rule".  Without the rule, we wouldn't know
what the dynamic type was during construction.  A language must define
it.

Java defines it differently.  I've had to track down a couple of
NullPointerException because of it, and add some special code to handle
the case where a function is called on an unconstructed object.
Admittedly, I get a NullPointerException, rather than undefined
behavior, and since Java always 0 initializes an object before calling
constructors, it is possible to test.  But having used both rules, I can
only say that C++ is a lot safer in this regard.  (The safest rule would
probably be that you cannot call a virtual function, period, until the
object is fully constructed.  However, I don't see any way the compiler
could enforce this, and the C++ rule is definitly preferrable to yet
another case of undefined behavior.)

--=20
James Kanze                               mailto:kanze@gabi-soft.de
Conseils en informatique orient=E9e objet/
                   Beratung in objektorientierter Datenverarbeitung
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



