class C
{
public:
C()
{
cout << "C constructor" << endl;
}
~C()
{
cout << "C destroy" << endl;
}
C(C &c)
{
cout << "C copy" << endl;
}
protected:
private:
};
class A
{
public:
A()
{
cout << "A constructor" << endl;
}
~A()
{
cout << "A destroy" << endl;
}
A(A &a)
{
cout << "A Copy" << endl;
}
virtual void Test()
{
cout << "Call A" << endl;
}
protected:
private:
//C c;
};
class B : public A
{
public:
B()
{
cout << "B constructor" << endl;
}
~B()
{
cout << "B destroy" << endl;
}
B(B &b)
{
cout << "B Copy" << endl;
}
void Test()
{
cout << "Call B" << endl;
}
protected:
private:
C c;
};
int main(int argc, _TCHAR* argv[])
{
B b;
return 0;
}
C 在父类A中构造顺序为
C constructor
A constructor
B constructor
B destroy
A destroy
C destroy
C 在子类B中构造顺序为
A constructor
C constructor
B constructor
B destroy
C destroy
A destroy