#include <iostream>
class ICloneable
{
public:
virtual ICloneable* Clone() const = 0;
};
class Player : public ICloneable
{
public:
ICloneable* Clone() const
{
return new Player(*this);
}
void SomeSpecificPlayerMethod() const
{
std::cout << "Specific Player Method!\n";
}
};
class GameObject : public ICloneable
{
public:
ICloneable* Clone() const
{
return new GameObject(*this);
}
void SomeSpecificGameObjectMethod() const
{
std::cout << "Some Specific Game Object Method!\n";
}
};
class SomeContainerNode
{
public:
SomeContainerNode(Player* pPlayer, GameObject* pGameObject)
: m_pPlayer(pPlayer)
, m_pGameObject(pGameObject)
{
}
SomeContainerNode()
: m_pPlayer(nullptr)
, m_pGameObject(nullptr)
{
}
Player* GetPlayer() const { return m_pPlayer; }
GameObject* GetGameObject() const { return m_pGameObject; }
void SetPlayer(Player* pPlayer) { m_pPlayer = pPlayer; }
void SetGameObject(GameObject* pGameObject) { m_pGameObject = pGameObject; }
private:
Player* m_pPlayer;
GameObject *m_pGameObject;
};
int main()
{
auto someContainer = SomeContainerNode(new Player(), new GameObject());
auto pPlayer = someContainer.GetPlayer();
pPlayer->SomeSpecificPlayerMethod();
auto pGameObject = someContainer.GetGameObject();
pGameObject->SomeSpecificGameObjectMethod();
return 0;
}