fork download
  1. #include <iostream>
  2.  
  3. class ICloneable
  4. {
  5. public:
  6. virtual ICloneable* Clone() const = 0;
  7. };
  8.  
  9. class Player : public ICloneable
  10. {
  11. public:
  12. ICloneable* Clone() const
  13. {
  14. return new Player(*this);
  15. }
  16.  
  17. void SomeSpecificPlayerMethod() const
  18. {
  19. std::cout << "Specific Player Method!\n";
  20. }
  21. };
  22.  
  23. class GameObject : public ICloneable
  24. {
  25. public:
  26. ICloneable* Clone() const
  27. {
  28. return new GameObject(*this);
  29. }
  30.  
  31. void SomeSpecificGameObjectMethod() const
  32. {
  33. std::cout << "Some Specific Game Object Method!\n";
  34. }
  35. };
  36.  
  37. class SomeContainerNode
  38. {
  39. public:
  40. SomeContainerNode(Player* pPlayer, GameObject* pGameObject)
  41. : m_pPlayer(pPlayer)
  42. , m_pGameObject(pGameObject)
  43. {
  44.  
  45. }
  46.  
  47. SomeContainerNode()
  48. : m_pPlayer(nullptr)
  49. , m_pGameObject(nullptr)
  50. {
  51.  
  52. }
  53.  
  54. Player* GetPlayer() const { return m_pPlayer; }
  55. GameObject* GetGameObject() const { return m_pGameObject; }
  56.  
  57. void SetPlayer(Player* pPlayer) { m_pPlayer = pPlayer; }
  58. void SetGameObject(GameObject* pGameObject) { m_pGameObject = pGameObject; }
  59. private:
  60. Player* m_pPlayer;
  61. GameObject *m_pGameObject;
  62. };
  63.  
  64. int main()
  65. {
  66. auto someContainer = SomeContainerNode(new Player(), new GameObject());
  67. auto pPlayer = someContainer.GetPlayer();
  68. pPlayer->SomeSpecificPlayerMethod();
  69.  
  70. auto pGameObject = someContainer.GetGameObject();
  71. pGameObject->SomeSpecificGameObjectMethod();
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Specific Player Method!
Some Specific Game Object Method!