#include
Using namespace std;
INT INC = 0;
String tab ()
{
String t;
T.Rserve (Inc 1);
For (int i = 0; i { T.push_back ('/ t'); } Return T; } Class base { PUBLIC: Base (void) { Inc ; COUT << Tab () << "Base :: CTOR ()" << endl; COUT << Tab () << "I am A" << TypeId (this) .Name () << endl; vfunc (); Func (); Inc-- } ~ base (void) { Inc ; Cout << Tab () << "Base :: ~ ctor () << endl; Inc-- } Base (Double D) { Inc ; Cout << Tab () << "Base :: CTOR (" << D << ")" << ENDL; COUT << Tab () << "I am A" << TypeId (this) .Name () << endl; vfunc (); Func (); Inc-- } Base (int a) { Inc ; COUT << Tab () << "Base :: CTOR (" << a << ")" << ENDL; COUT << Tab () << "I am A" << TypeId (this) .Name () << endl; vfunc (); Func (); Inc-- } Virtual void vfunc (void) { Inc ; COUT << Tab () << "Base :: Virtual function ()" << endl; Inc-- } Void func (void) { Inc ; COUT << Tab () << "Base :: function () << endl; Inc-- } Void Call (void) { Inc ; COUT << Tab () << "Base :: Call ()" << endl; vfunc (); Func (); Inc-- } } Class Child: Public base { PUBLIC: Child (void) { Inc ; COUT << Tab () << "Child :: CTOR () << endl; COUT << Tab () << "I am A" << TypeId (this) .Name () << endl; vfunc (); Func (); Inc-- } ~ Child (void) { Inc ; COUT << Tab () << "Child :: ~ CTOR ()" << endl; Inc-- } Child (double d) { Inc ; COUT << Tab () << "Child :: CTOR (" << D << ")" << endl; COUT << Tab () << "I am A" << TypeId (this) .Name () << endl; vfunc (); Func (); Inc-- } CHild (Int a): base (a) { Inc ; COUT << Tab () << "Child :: CTOR (" << a << ")" << ENDL; COUT << Tab () << "I am A" << TypeId (this) .Name () << endl; vfunc (); Func (); Inc-- } Virtual void vfunc (void) { Inc ; COUT << Tab () << "Child :: virtual function ()" << endl; Inc-- } Void func (void) { Inc ; COUT << Tab () << "Child :: function () << endl; Inc-- } } Int main (void) { COUT << Tab () << "Before Create B" << Endl; Base B; COUT << Tab () << "After Create B" << ENDL; B.Vfunc (); B.func (); b.call (); COUT << "-----------------" e e; COUT << Tab () << "Before Create C" << Endl; CHILD C; COUT << Tab () << "after create c" << end1 C.Vfunc (); C.func (); C.call (); COUT << "-----------------" e e; Cout << Tab () << "Before Create C1" << ENDL; Child C1 (1); COUT << Tab () << "After Create C1" << ENDL; C1.Vfunc (); C1.func (); c1.call (); COUT << "-----------------" e e; COUT << Tab () << "Before CREATE C2" << ENDL; Child C2 (1.1); COUT << Tab () << "After Create C2" << ENDL; C2.Call (); } Run results: Before Create B Base :: ctor () I am a p4base Base :: virtual function () Base :: function () After Create B Base :: virtual function () Base :: function () Base :: Call () Base :: virtual function () Base :: function () ----------------- Before create C Base :: ctor () I am a p4base Base :: virtual function () Base :: function () Child :: ctor () I am a p5child Child :: virtual function () Child :: function () After Create C Child :: virtual function () Child :: function () Base :: Call () Child :: virtual function () Base :: function () ----------------- Before create C1 Base :: ctor (1) I am a p4base Base :: virtual function () Base :: function () Child :: ctor (1) I am a p5child Child :: virtual function () Child :: function () After Create C1 Child :: virtual function () Child :: function () Base :: Call () Child :: virtual function () Base :: function () ----------------- Before create C2 Base :: ctor () I am a p4base Base :: virtual function () Base :: function () Child :: ctor (1.1) I am a p5child Child :: virtual function () Child :: function () After Create C2 Base :: Call () Child :: virtual function () Base :: function () Child :: ~ ctor () Base :: ~ ctor () Child :: ~ ctor () Base :: ~ ctor () Child :: ~ ctor () Base :: ~ ctor () Base :: ~ ctor ()