0

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.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
Ian Young
  • 1,712
  • 1
  • 16
  • 33
  • 1
    @0x499602D2: Don't abuse the insta-close powers. This is clearly not a "typical" undefined reference problem. – Lightness Races in Orbit May 21 '14 at 00:33
  • where are you defining the "Entity" class? Are you sure you implement its methods and link the corresponding `c++` file? – vsoftco May 21 '14 at 00:35
  • Yes, the Entity class is defined in it's own .h/.cpp file pair and the header is included in the EntityManager.h file. I tested this by removing all Entity method calls, and the error persists. Where it fails is checking mEntities[i] to see if it is null. – Ian Young May 21 '14 at 00:39
  • When I remove all mEntities[i] statements, the project compiles without error or warning. – Ian Young May 21 '14 at 00:44
  • And you are right! I changed the preprocessor setting to NDEBUG and the project now compiles perfectly. Kudos and many thanks. – Ian Young May 21 '14 at 01:14

0 Answers0