I have 2 static lists. EntityList::EnemyList, which is a list of enemies, and EntityList::MasterList, which is a list of pointers to ALL entities, like enemies, the player, bullets, etc.
In my factory function for entities, I have this code, which creates a new Enemy object:
This works fine, but as soon as I create more than one enemy, the pointer in MasterList apparently becomes invalid because the vector is resized and repositioned.
This code works, but there is a memory leak:
Is there a happy medium here? Neither works 100%. I was thinking smart pointers but those would just go out of scope after the function, no?
Enemy *ent=new Enemy();