I need a custom insert / add member function for my "entity manager class" which is only responsible of many entities. For this I define a std::vectorstd::unique_ptr<cEntity> listOfEntities as private in this class. But how can I add entities to the vector?
Following situation:
class cEntity
{
public:
void setName(const std::string& newName)
{
name = newName;
};
private:
std::string name;
};
class cEntityMgr
{
public:
cEntityMgr() { listOfEntities.clear(); };
void addEntity(const cEntity& aEntity)
{
listOfEntities.push_back(aEntity); // this doesn´t work
};
private:
std::vector<std::unique_ptr<cEntity>> listOfEntities;
};
int main()
{
//
cEntityMgr myFirstEntityMgr;
// add a new entity to my entity manager
myFirstEntityMgr.addEntity(std::make_unique<cEntity>("My First Entity") ); // I don´t want to use any new call here
}