This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Constructors and multiple virtual inheritance -- bug or feature?
- To: egcs-bugs at cygnus dot com
- Subject: Constructors and multiple virtual inheritance -- bug or feature?
- From: csk at cs dot washington dot edu (Craig Kaplan)
- Date: Tue, 8 Dec 1998 21:52:26 -0800 (PST)
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?