1#include <iostream>2 using namespacestd;3 classObject {4 public:5Object (intTest): A (1), B (2), C (3) {cout <<"object construction \ n"; }6~Object ()7 {8cout <<"object destructor \ n";9 }Ten inta; one intb; a intc; - voidsame_fuc () - { thecout <<"Object test...\n"; - } - voidO_print () - { +cout <<"a b c is"<< a <<" "<< b <<" "<< C <<endl; - } + a }; at classParent: publicObject { - public: -Parent (intTest): Object (1), A ( -), B ( $), C ( -), Obj1 (1), Obj2 (2)//note - { -cout <<"Parent Construct ... \ n"; - } in~Parent () - { tocout <<"Parent Destruction ... \ n"; + } - inta; the intb; * intc; $ voidsame_fuc ()Panax Notoginseng { -cout <<"Parent test...\n"; the } + voidP_print () a { thecout <<"a b c is"<< a <<" "<< b <<" "<< C <<endl; + } - Object obj1; $ Object obj2; $ }; - classChild: publicParent - { the public: -Child ():P Arent (1), A ( +), B ( -), C ( the) {cout <<"child construct \ n"; }Wuyi~child () the { -cout <<"Child destructor,, \ n"; wu } - voidC_print () about { $cout <<"a b c is"<< a <<" "<< b <<" "<< C <<endl; - } - voidsame_fuc () - { acout <<"child test...\n"; + } the inta; - intb; $ intc; the }; the the intMain () the { - in child c1; the C1.c_print (); thec1.a =520;//the default is equivalent to c1. child::a=520; about C1.c_print (); thec1. Parent::a =5200; the C1.p_print (); the C1.c_print (); +c1. Object::a =52000; - C1.o_print (); the C1.c_print ();Bayi theC1.same_fuc ();//the default is equivalent to c1. Child::same_fuc (); the c1. Parent::same_fuc (); - c1. Object::same_fuc (); - return 0; the}
C + +--the name of the named member and function invocation of the derived class and the construction of the destructor sequence