Guest User

Untitled

a guest
Sep 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class Player
  2. {
  3. public:
  4. Player();
  5. Player(&Player) const;
  6.  
  7. private:
  8. Item * item;
  9. }
  10.  
  11. class Item
  12. {
  13. public:
  14. Item();
  15. void virtual Use();
  16. }
  17.  
  18. class Sword : public Item
  19. {
  20. public:
  21. Sword();
  22. void virtual Use();
  23. }
  24.  
  25. Player::Player()
  26. {
  27. item = new Sword();
  28. }
  29.  
  30. Player::Player(&Player p)
  31. {
  32. item = new Item(*(p.item));
  33. }
  34.  
  35. class Player
  36. {
  37. public:
  38. Player();
  39. Player(&Player) const;
  40.  
  41. private:
  42. Item * item;
  43. }
  44.  
  45. Player::Player(&Player p)
  46. {
  47. item = new Item(*(p.item));
  48. }
  49.  
  50. class Item
  51. {
  52. public:
  53. Item();
  54. virtual void Use();
  55. virtual Item* Clone() const =0;
  56. }
  57.  
  58. class Sword : public Item
  59. {
  60. public:
  61. Sword();
  62. void Use();
  63. Item* Clone() const { return new Sword (*this); }
  64. }
  65.  
  66. Player::Player(const Player& p)
  67. {
  68. item = p.item->Clone();
  69. }
Add Comment
Please, Sign In to add comment