From -8289769610306207823
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,3cdb654b702f7476
X-Google-Attributes: gidf78e5,public
From: llewelly.@@edevnull.dot.com
Subject: Re: virtual functions
Date: 2000/08/18
Message-ID: <m2hf8jigxk.fsf@brownie.frogger.foobar.snot>#1/1
X-Deja-AN: 659692236
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <399A78E4.8345D7B@gmx.at> <m23dk5jiuq.fsf@brownie.frogger.foobar.snot> <399B8FA6.540D5B7F@gmx.at>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 966597940 mail2news:4425 mail2news mail2news.demon.co.uk
Organization: XMission http://www.xmission.com/
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
User-Agent: Gnus/5.0806 (Gnus v5.8.6) Emacs/20.7
Mime-Version: 1.0
NNTP-Posting-Date: 17 Aug 2000 23:52:37 GMT
Newsgroups: comp.std.c++

"Gerhard W. Gruber" <sparhawk@gmx.at> writes:

> "llewelly."@@edevnull.dot.com wrote:
> 
> > Your compiler is correct in this case; if a virtual function is called
> >   from inside a constructor, the method of that class - *not* the
> >   overriding method - is called.
> 
> Is this only true for the constructor? From your statement it appears
> so, but I'm not sure on this.

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

> 
> > It seems to me that a virtual initialization method such as what you
> >   want implies a close coupling between the implementation of the base
> >   class's constructor and the derived class. How could the author of
> >   the overriding virtual initialization method know what to
> >   initialize without understanding the implementation of the base
> >   class's constructor? Such tight coupling is usually poor design, as
> >   it makes derived classes likely to break when the implementation of
> >   the base class is changed.
> 
> I don't really see why this should be poor design. When I call the base
> class constcructor, I can assume that the class is properly initialized
> (That's what the constructor is for, isnt't it?). So when the base class
> constructor returns I can change part of the initialization in the
> derived class that fits the derivation. Isn't that so?

I think we are talking about two different things. I had the
  impression that the virtual initialization function was to be called 
  *before* the base class constructor had returned.

Reconfiguring the base class sub object after it has been correctly
  initialized seems less error prone.

[snip]

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




