class A {
int i;
public:
A() {cout<<"in A's def const
";};
A(int k) {cout<<"In A const
"; i = k; }
};
class B : virtual public A {
public:
B(){cout<<"in B's def const
";};
B(int i) : A(i) {cout<<"in B const
";}
};
class C : public B {
public:
C() {cout<<"in C def cstr
";}
C(int i) : B(i) {cout<<"in C const
";}
};
int main()
{
C c(2);
return 0;
}
The output in this case is
in A's def const
in B const
in C const
Why is this not entering into in A const
`It should follow the order of 1 arg constructor call.
But what actually is happening on deriving B from A using virtual keyword.
There are few more question
Even if I remove the virtual keyword in above program and remove all the default constructor it gives error. So, why it needs the def constructor
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…