Multiple Inheritance in C++

  1. * /program to illustrate multiple inheritance./ *   
  2. #include < iostream > using namespace std;  
  3. class M  
  4. {  
  5.     protectedint m;  
  6.     publicvoid get(int);  
  7. };  
  8. class N  
  9. {  
  10.     protectedint n;  
  11.     publicvoid getdata(int);  
  12. };  
  13. class P: public M, public N  
  14. {  
  15.     publicvoid display(void);  
  16. };  
  17. void M::get(int x)  
  18. {  
  19.     m = x;  
  20. }  
  21. void N::getdata(int y)  
  22. {  
  23.     n = y;  
  24. }  
  25. void P::display(void)  
  26. {  
  27.     cout << "\nm=" << m;  
  28.     cout << "\nn=" << n;  
  29.     cout << "\nm * n:" << m * n;  
  30. }  
  31. int main()  
  32. {  
  33.     P obj;  
  34.     obj.get(10);  
  35.     obj.getdata(20);  
  36.     obj.display();  
  37.     return 0;  
  38. }