J
jeffc
When compiling the following program, I get an error on the line specified:
The base class "B" cannot be initialized because it does not have a default
constructor.
If I remove the "virtual" inheritance of B (so that it uses plain
inheritance), it compiles fine. It also compiles if I invoke the
constructor for B explicitly, as shown in the comment after the error. I'm
not aware of any reason that virtual inheritance should be special in this
respect. What's wrong?
class B
{
public:
B(int){}
};
class C : virtual public B
{
public:
C():B(1){}
};
class D : public C
{
public:
D(){} // error here
// D():B(1){} - this however compiles OK
};
int main()
{
return 0;
}
The base class "B" cannot be initialized because it does not have a default
constructor.
If I remove the "virtual" inheritance of B (so that it uses plain
inheritance), it compiles fine. It also compiles if I invoke the
constructor for B explicitly, as shown in the comment after the error. I'm
not aware of any reason that virtual inheritance should be special in this
respect. What's wrong?
class B
{
public:
B(int){}
};
class C : virtual public B
{
public:
C():B(1){}
};
class D : public C
{
public:
D(){} // error here
// D():B(1){} - this however compiles OK
};
int main()
{
return 0;
}