This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Constructors and multiple virtual inheritance -- bug or feature?


Sorry about a possible repeat -- I may have messed up my original post.

Hi all,

I recently had the following C++ compilation experience:

--------------------- b.c++ ---------------------
    class A
    {
    public:
            A( int ) {}
    };

    class B : virtual public A
    {
    public:
            B( int x ) : A( x ) {}
    };

    class C : virtual public A
    {
    public:
            C( int x ) : A( x + 12 ) {}
    };

    class D : public B, public C
    {
			public: D( int x ) : A( 12 ), B( x - 4 ), C( x + 8 ) {}
    };

    class E : public D
    {
    public:
            E( int x ) : D( 99 ) {}
    };

    int main( void )
    {
            A * a = new E( 27 );
    }
------------------------------------------------

    % g++ --version
    egcs-2.91.60
    % g++ -o b b.c++
    b.c++: In method `E::E(int)':
    b.c++:27: no matching function for call to `A::A ()'
    b.c++:5: candidates are: A::A(const A &)
    b.c++:4:                 A::A(int)

I can understand why D needs to explicitly call A's constructor -- for
if not, then the initialization of A is ambiguous.  But it's by no means
ambiguous for E, since E's constructor can rely on D's constructor to
initialize the A part.

Is this a bug?  Is this a C++ "feature"?  If it's a feature, it seems 
misguided.  I should be able to singly inherit from any class without 
having to know about the initialization nightmares of its ancestry.

I guess I hope it's a bug.

Thanks!

-- 
Craig.              http://www.cs.washington.edu/homes/csk/
Counterfactuals: what would the world be like without them?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]