class Base{public: Base() { Fuction(); } virtual void Fuction() { cout << " construct Base::Fuction" << endl; } ~Base() { desFuction(); } virtual void desFuction() { cout << " destruct Base::Fuction" << endl; }};class A : public Base{public: A() { Fuction(); } ~A() { desFuction(); } virtual void Fuction() { cout << " construct A::Fuction" << endl; } virtual void desFuction() { cout << " destructr A::Fuction" << endl; }};int test(){ A a; return 0;}
输出结果:
cout << " construct Base::Fuction" << endl;
cout << " construct A::Fuction" << endl;
cout << " destructr A::Fuction" << endl;
cout << " destruct Base::Fuction" << endl;