Construction and destruction of multiple succession and multiple inheritance of single inheritance

Source: Internet
Author: User

Single Inheritance multiple times

Code:

classgreat_great_father{ Public: Great_great_father () {cout<<"function: \tgreat_great_father ()"<<Std::endl; }    ~Great_great_father () {cout<<"function: \t~great_great_father ()"<<Std::endl; }};classGreat_father: Publicgreat_great_father{ Public: Great_father () {cout<<"function: \tgreat_father ()"<<Std::endl; }    ~Great_father () {cout<<"function: \t~great_father ()"<<Std::endl; }};classFather: Publicgreat_father{ Public: Father () {cout<<"function: \tfather ()"<<Std::endl; }    ~father () {cout<<"function: \t~father ()"<<Std::endl; }};classSon: Publicfather{ Public: Son () {cout<<"function: \tson ()"<<Std::endl; }    ~Son () {cout<<"function: \t~son ()"<<Std::endl; }};intMainintargcChar*argv[])    {{son S; } System ("Pause"); return 0;}

Son S; The statement is placed in a block of code so that the destructor is placed before the main function ends.

The class diagram is as follows

Operation Result:

Multiple inheritance

Code:

classfather1{ Public: Father1 () {cout<<"function: \tfather1 ()"<<Std::endl; }    ~Father1 () {cout<<"function: \t~father1 ()"<<Std::endl; }};classfather2{ Public: Father2 () {cout<<"function: \tfather2 ()"<<Std::endl; }    ~Father2 () {cout<<"function: \t~father2 ()"<<Std::endl; }};classfather3{ Public: Father3 () {cout<<"function: \tfather3 ()"<<Std::endl; }    ~Father3 () {cout<<"function: \t~father3 ()"<<Std::endl; }};classSon: PublicFather1, PublicFather2, Publicfather3{ Public: Son () {cout<<"function: \tson ()"<<Std::endl; }    ~Son () {cout<<"function: \t~son ()"<<Std::endl; }};intMainintargcChar*argv[])    {{son S; } System ("Pause"); return 0;}

Class Diagram:

Operation Result:

Compiler: Visual Studio cl.exe

Practice is very interesting!

Construction and destruction of multiple succession and multiple inheritance of single inheritance

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.