Multi-Inheritance format:
Class Name: Inheritance Mode 1 base class 1, inheritance Method 2 base class 2, ...
#include <iostream>using namespace Std;class x{int x;public:x (int a = 0) {X = a;cout<< "Constructing X "<<X<<ENDL;} void set_x (int a) {x = A;} void show_x () {cout<< "x =" <<X<<ENDL;} ~x () {cout<< "destructing X" <<x<<endl;}}; Class y{int y;public:y (int a = 0) {Y = a;cout<< "Constructing Y" <<Y<<ENDL;} void set_y (int b) {y = b;} void Show_y () {cout<< "y =" <<y<<endl;;} ~y () {cout<< "destructing Y" <<y<<endl;}}; Class Z:public X,public y//multiple inheritance {int z;public:z (int a = 0,int b = 0,int c = 0): X (a), Y (b) {Z = C; cout<< "Constructing Z" <<z<<endl; } void set_xyz (int a,int b,int c) {set_x (a); Set_y (b); z = c; } void Show_z () {cout<< "z =" <<z<<endl; } void Show () {show_x (); Show_y (); cout<< "z = "<<z<<endl;//class can be used directly} ~z () {cout<<" Destructing z "<<z<<endl;}}; int main () {Z obj1 (3,4,5); Z Obj2; OBJ2.SET_XYZ (10,20,30); Obj1.show_x (); Obj1.show_y (); Obj1.show_z (); Obj2.show (); return 0;}
[C + +] multiple inheritance