Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class C {
  2. public:
  3. C();
  4. virtual ~C();
  5.  
  6. C(int x)
  7. {
  8. y = x;
  9. }
  10. void print()
  11. {
  12. cout << y << endl;
  13. }
  14.  
  15. private:
  16. int y;
  17. };
  18.  
  19. class B : public virtual C {
  20. public:
  21. B();
  22. virtual ~B();
  23. B(int x)
  24. : C(x)
  25. {
  26. }
  27. };
  28.  
  29. class A : public virtual C {
  30. public:
  31. A();
  32. virtual ~A();
  33.  
  34. A(int y)
  35. : C(y)
  36. {
  37. }
  38. };
  39.  
  40. class D : public B, public A {
  41. public:
  42. D();
  43. virtual ~D();
  44.  
  45. D(int x)
  46. : B(x)
  47. , A(x)
  48. {
  49. }
  50. };
  51.  
  52. C* a = new D(3);
  53.  
  54. a->print();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement