Consider the code below. Both g++ and clang++ complain (correctly) that the constructor A(int)
is private in class D
. Note that, as A
is a virtual base class of D
, A
has to be initialized in the mem-initializer of class D
, the most derived class, according to §12.6.2/7 in C++11. See live example.
class A {
public:
A(int i) : x(i) { }
A() : x(1) {}
int x;
};
class B : private virtual A {
protected:
B(int i) : A(i) { } };
class C : public B, private virtual A {
protected:
C(int i) : A(i), B(i) { }
};
class D : public C {
public:
D() : A(1), C(3) { }
};
int main() {
D d;
}
But both compilers don't bother with the fact that the default constructor for class A
is also private in D
, i.e., both compile and execute the code normally, if we define the constructor for D
as follows:
D() : C(3) {}
And this is wrong, as far as I can tell.
Note that both compilers fail to compile (correctly) if we define:
D() : A(), C(3) {}
D() : C(3) {}
– Shafik YaghmourD(): C(3) {}
pointed above? I'm asking this because I really don't know the difference between the compiler I used in Coliru (the standard std=C++11) and 4.7.3 that you mentioned above – BellocD() : C(3)
, I get no error with GCC 4.7.4. Which command-line options are you using with 4.7.3 to get an error for that? – user743382error: 'class A A::A' is inaccessible
on ideone: ideone.com/n9ywWo – drescherjm