I am trying to write an Entity Manager class, which will store and maintain a vector of shared pointers of type Entity:
std::vector<std::shared_ptr<Entity>> mEntities;
The vector is filled like so:
mEntities.resize(maxEntities, std::make_shared<Entity>());
I have written a member function into the class which returns an Entity shared pointer:
std::shared_ptr<Entity> EntityManager::getEntity()
{
for (std::size_t i = 0; i < mEntities.size(); ++i)
{
if (mEntities[i]!=nullptr)
{
mEntities[i] = std::make_shared<Entity>();
}
if (!mEntities[i]->Alive() && !mEntities[i]->InUse())
{
mEntities[i]->revive();
mEntities[i]->setID((unsigned int)i);
mEntities[i]->activate();
return mEntities[i];
}
}
return nullptr;
}
This throws a compiler error:
Error 1 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class std::shared_ptr<class Entity> & __thiscall std::vector<class std::shared_ptr<class Entity>,class std::allocator<class std::shared_ptr<class Entity> > >::operator[](unsigned int)" (??A?$vector@V?$shared_ptr@VEntity@@@std@@V?$allocator@V?$shared_ptr@VEntity@@@std@@@2@@std@@QAEAAV?$shared_ptr@VEntity@@@1@I@Z)
This seems to indicate that the operator[]
is failing somehow, unless I am misreading the error message.
Additional: I should have pointed out that All methods on the the Entity type have been implemented, so I know it cannot be related to the class itself.