fork download
  1. #include <iostream>
  2.  
  3. class Drawable
  4. {
  5. public:
  6. int x;
  7. int y;
  8. Drawable()
  9. {
  10. x = 0;
  11. y = 0;
  12. }
  13. };
  14.  
  15. class Ball : public Drawable
  16. {
  17. public:
  18. int xdir;
  19. int ydir;
  20. Ball()
  21. {
  22. xdir = 1;
  23. ydir = 1;
  24. }
  25. void move();
  26. };
  27.  
  28. void Ball::move()
  29. {
  30. x += xdir;
  31. y += ydir;
  32. }
  33.  
  34. class Game
  35. {
  36. public:
  37. Drawable* drawables;
  38. Game() {}
  39. };
  40.  
  41. class Pong : public Game
  42. {
  43. public:
  44. Ball ball;
  45. Pong()
  46. {
  47. drawables = new Drawable[1];
  48. drawables[0] = ball;
  49. }
  50. };
  51.  
  52. int main()
  53. {
  54. Pong pongGame;
  55.  
  56. std::cout << pongGame.drawables[0].x << std::endl;
  57. std::cout << pongGame.ball.x << std::endl;
  58.  
  59. pongGame.ball.move();
  60.  
  61. std::cout << pongGame.drawables[0].x << std::endl;
  62. std::cout << pongGame.ball.x << std::endl;
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
0
0
0
1