fork(1) download
  1.  
  2. #include<iostream>
  3. using namespace std;
  4. class shape
  5. {
  6. public:
  7. shape()
  8. {
  9. cout << "shape created" << endl;
  10. }
  11. virtual void draw()=0;
  12.  
  13.  
  14. };
  15. class circle : public virtual shape
  16. {
  17. public:
  18. circle()
  19. {
  20. cout << "circle created" << endl;
  21. }
  22. virtual void draw()
  23. {
  24. cout << "this is a circle" << endl;
  25. }
  26. };
  27. class square : public virtual shape
  28. {
  29. public:
  30. square()
  31. {
  32. cout << "square created" << endl;
  33. }
  34. virtual void draw()
  35. {
  36. cout << "this is a square" << endl;
  37. }
  38. };
  39. class shapes : public circle, public square
  40. {
  41. public:
  42. shapes()
  43. {
  44. cout << "shapes created" << endl;
  45. }
  46.  
  47. virtual void draw()
  48. {
  49. circle::draw();
  50. square::draw();
  51. }
  52. };
  53. int main()
  54. {
  55. shapes e;
  56. cout << "-------------" << endl;
  57. e.draw();
  58. return 0;
  59. }
Success #stdin #stdout 0s 3144KB
stdin
Standard input is empty
stdout
shape created
circle created
square created
shapes created
-------------
this is a circle
this is a square