fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class B1{
  5. int a;
  6. public:
  7. B1(int x): a(x) {}
  8. void show() { cout <<"B1= "<< a << "\n"; }
  9. };
  10.  
  11. class B2{
  12. int b;
  13. public:
  14. B2(int x) { b=x; }
  15. void show() { cout << "B2= "<< b << "\n";}
  16. };
  17.  
  18. class D1: public B1, public B2{
  19. int c;
  20. public:
  21. D1(int x, int y, int l) : c(x), B1(y), B2(l) {};
  22. void show() { cout <<"D1= "<< c << "\n"; B1::show(); B2::show();}
  23. };
  24.  
  25. class D2 {
  26. int d;
  27. public:
  28. D2(int x): d(x) {};
  29. void show() { cout <<"D2= "<< d << "\n"; }
  30. };
  31.  
  32. class D3: public D1, public D2 {
  33. int e;
  34. public:
  35. D3(int a, int b, int c, int d, int x):e(x),D1(a,b,c),D2(d) {}
  36. void show() {cout <<"D3= "<< e << "\n"; D1::show(); D2::show();}
  37. };
  38. class D4: public D3 {
  39. int f;
  40. public:
  41. D4(int x, int i, int p, int q, int e, int k): f(x), D3(i,p,q,e,k) {};
  42. void show() { cout <<"D4= "<< f << "\n"; D3::show() ;}
  43. };
  44.  
  45. int main() {
  46. D2 temp(100);
  47. D4 temp1(1,2,3,4,5,6);
  48. cout << "D2 temp(100,200,300,400,500);\n";
  49. cout << "D4 temp1(1,2,3,4,5);\n";
  50. cout<< "\nСледуя иерархии класса D4\n";
  51. temp1.show();
  52. }
  53.  
Success #stdin #stdout 0s 4356KB
stdin
Standard input is empty
stdout
D2 temp(100,200,300,400,500);
D4 temp1(1,2,3,4,5);

Следуя иерархии класса D4
D4= 1
D3= 6
D1= 2
B1= 3
B2= 4
D2= 5