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