Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Player
- {
- public:
- Player();
- Player(&Player) const;
- private:
- Item * item;
- }
- class Item
- {
- public:
- Item();
- void virtual Use();
- }
- class Sword : public Item
- {
- public:
- Sword();
- void virtual Use();
- }
- Player::Player()
- {
- item = new Sword();
- }
- Player::Player(&Player p)
- {
- item = new Item(*(p.item));
- }
- class Player
- {
- public:
- Player();
- Player(&Player) const;
- private:
- Item * item;
- }
- Player::Player(&Player p)
- {
- item = new Item(*(p.item));
- }
- class Item
- {
- public:
- Item();
- virtual void Use();
- virtual Item* Clone() const =0;
- }
- class Sword : public Item
- {
- public:
- Sword();
- void Use();
- Item* Clone() const { return new Sword (*this); }
- }
- Player::Player(const Player& p)
- {
- item = p.item->Clone();
- }
Add Comment
Please, Sign In to add comment