Consider the code below. Both compilers 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) {}
Aucun commentaire:
Enregistrer un commentaire