From 314747446700334546
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,2c39b838f9d484c1
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-08-30 13:00:06 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news.cis.ohio-state.edu!news.maxwell.syr.edu!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: Andrey Tarasevich <andreytarasevich@hotmail.com>
Newsgroups: comp.std.c++
Subject: Re: Virtual Base-class constructor calls
Date: 30 Aug 2002 20:00:05 GMT
Organization: Newsfeed.com http://www.newsfeed.com 100,000+ UNCENSORED Newsgroups.
Lines: 42
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3D6FC9D0.D233ED0C@hotmail.com>
References: <5fcc5166.0208301024.506d52e3@posting.google.com> <umvgbph675a1f1@corp.supernews.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Return-Path: <devnull@stump.algebra.com>
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)
Delivered-To: std-c++@ncar.ucar.edu
X-Accept-Language: en
X-Authenticated-User: clairvoyant
X-Comments: This message was posted through Spamkiller.Newsfeeds.com
X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support,  spam or any illegal or copyrighted postings.
X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!!
X-Report: Please report illegal or inappropriate use to <abuse@newsfeeds.com> You may also use our online abuse reporting from: http://www.newsfeeds.com/abuseform.htm
X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS)
X-OriginalArrivalTime: 30 Aug 2002 19:38:27.0734 (UTC) FILETIME=[D00A3B60:01C2505C]
Xref: archiver1.google.com comp.std.c++:13500

Victor Bazarov wrote:
> ...
> > Any class which derives from a virtual base-class (through any number
> > of levels of inheritance), must call the constructor of the virtual
> > base class. The only invocation which is actually used, however, is
> > the one for the class actually being constructed.
> >
> > Thus, in the following example classes B and C must call the A ctor
> > even though their invocation is never used since they are never
> > allocated.
> >
> > My only suggestion is that B and C be permitted to not call the A ctor
> > since they are both pure virtual and cannot be allocated.
> 
> What if I write another class that derives from B but not
> from C, and which implements f()?  I will have no way to
> initialise A, so I will have to rely on B's constructor for
> the initialisation with a number.
> ...

I don't see how it makes any difference. 'A' is virtual base class of
'B'. Even if you define class, say, 'X' that derives only from 'B',
you'll still have to initialize 'A' from 'X's initializer list in 'X's
constructor. It doesn't matter whether there are five, two or only one
way from 'A' to 'X' in the inheritance diagram, a virtual base class
remains a virtual base class. It will always be initialized in
accordance with the initializer list in most derived object's
constructor. 

I don't understand why you say "I will have no way to initialize A". Of
course you will have a way to initialize it.

Best regards,
Andrey Tarasevich,
Brainbench C and C++ Programming MVP

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]



