In the following code, it seems class C does not have access to A's constructor, which is required because of the virtual inheritance. Yet, the code still compiles and runs. Why does it work?
class A {};
class B: private virtual A {};
class C: public B {};
int main() {
C c;
return 0;
}
Moreover, if I remove the default constructor from A, e.g.
class A {
public:
A(int) {}
};
class B: private virtual A {
public:
B() : A(3) {}
};
then
class C: public B {};
would (unexpectedly) compile, but
class C: public B {
public:
C() {}
};
would not compile, as expected.
Code compiled with "g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)", but it has been verified to behave the same with other compilers as well.
According to C++ Core Issue #7 class with a virtual private base can't be derived from. This is a bug in compiler.