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: Alexandre Oliva <aoliva at redhat dot com>
- Subject: Re: Non-default ctors, virtual base classes, & multiple inheritance all at once!
- From: sidster <patrick at mail dot boxsoft dot com>
- Date: Wed, 6 Sep 2000 09:33:03 -0700
- Cc: scherrey at switchco dot com, gcc at gcc dot gnu dot org
- References: <39B5343C.AB738C1C@switchco.com> <orvgw9byst.fsf@guarana.lsd.ic.unicamp.br>
Greetings,
* Alexandre Oliva (aoliva@redhat.com) [20000906 07:45]:
> On Sep 5, 2000, Benjamin Scherrey <scherrey@switchco.com> wrote:
>
> > 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?
>
> The latter. It is the most derived class that must construct all
> virtual base classes, even indirect ones. If it doesn't, default
> constructors are used, even if other base classes specify constructor
> arguments for virtual bases.
If I understand what you are suggesting correctly then it is
_impossible_ to get the desired behavior with the given code.
Since template <typename X> class HoldX has no knowledge of what
base classes X might have to even provide constructors to specify
them in its "mem-initializer-list".
In other words all template classes with template parameter classes
containing virtual bases classes (direct or indirect) are restricted
to using/initializing only the default constructors of these virtual
base classes. ???
I'm not sure about you but this strikes me as /quite odd/!
If this is true ... then there is a HUGE limitation in the C++
language!
I don't think this makes sense at all. Can you please provide us with
a reference to this behavior/limitation in the standard?
The only section I find is the following:
[12.6.2 Initializing bases and members]
//
// Initialization shall proceed in the following order:
//
// - First, and only for the constructor of the most derived class
// as described below, virtual base classes shall be initialized
// in the order they appear on a depth-first left-to-right
// traversal of the directed acyclic graph of base classes, where
// "left-to-right" is the order of appearance of the base class
// names in the derived class base-specifier-list.
Which seems to be supporting your point. Which, originally I wasn't too
sure if it actually meant *all virtual base classes* (including direct
and indirect).
But the more i read the above it is more clear that that is in-fact what
it means.
The only possible way of getting the intended behavior from the given
code would be to write a "wrapper" class to be the most derived class
and specify the desired constructors of the virtual base classes in its
"mem-initializer-list".
Eeeek! Talk about a hack, error prone, tedious and a maintenance
nightmare!
Please correct me if i'm wrong. Originally I was going to discard this
thread but now it's become more interesting :>
patrick
--
when i grow up i want to be a famous rock'n roll guitar player
-- steve vai