C + +--the member of the same name and the method of function invocation and the construction destruction order of derived classes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.