This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Non-default ctors, virtual base classes, & multiple inheritance all at once!
- To: llewelly at edevnull dot com
- Subject: Re: Non-default ctors, virtual base classes, & multiple inheritance all at once!
- From: Benjamin Scherrey <scherrey at switchco dot com>
- Date: Wed, 06 Sep 2000 01:40:48 -0400
- CC: gcc at gcc dot gnu dot org, scherrey at switchco dot com
- Organization: Proteus Technologies, Inc.
- References: <OF07792A8F.C99999F6-ON86256951.006954DE@com> <m11yyycvqe.fsf@edevnull.com>
- Reply-To: scherrey at switchco dot com
Bless you my son! I have been going nuts with this thing. I could not find
this in any of my references. I'll probably run across it about two months
from now.... Thanx!
llewelly@edevnull.com wrote:
> rlau@csc.com writes:
>
> > Please respond to scherrey@switchco.com
> > I'm having some trouble getting non-default constructors called for
> > virtual baseclasses in certain instances.. I've attached some code that
> > demonstrates this problem. In some cases, I can pass a parameter up the
> > tree to the virtual base class, in others, the default ctor is always
> > called even though my code clearly specifies the ctor taking a parm. Is
> > this a compiler bug or a language design issue?
>
> Language design.
>
> Constructors of virtual base classes are called from the constructor
> of the most derived class.
>
> The reason is that any data members in a virtual base class must
> appear only once in the final object, and must therefor only be
> initialized once. Calling the constructor from the constructor of
> the final type is how the langauge ensures this.
>
> For a full explanation, ask comp.lang.c++.moderated