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.
还有几个问题:
即使我删除上述方案中的虚拟关键词,删除所有违约构造,也会造成错误。 因此,它为什么需要造物