I have a map that stores pointers to an object by their identifier.
typedef std::map<unsigned int, Entity*> entityMap;
entityMap entitymap;
To assign an identifier to an object, I could just take the newest value in the entitymap file and increment it by 1.
Entity *entity = new Entity;
entity->id = ;
entitymap.insert(std::pair<unsigned int,Entity*>(entity->id,entity));
But the number can become unnecessarily large, because from time to time the Essence is deleted and removed from the card.
std::map<unsigned int,Entity*>::iterator it;
it = entitymap.find(EntityID);
if(it != entitymap.end())
{
Entity *entity= it->second;
entitymap.erase(it);
}
delete entity;
So I could have a map containing these values;
1,2,4,8,10
In this case, I would like the next Entity to request an identifier 3.
source
share