sab...@ve... wrote:
>though I haven't seen any solution. Any help is greatly appreciated. BTW feel
>free to make comments on the code design too!
>
>
The end() element doesn't exist in a contaier, it's the
"one-after-the-last" element.
If you want to remove the last element with "->ID == ID", I would do it
like this:
---
class compare_id {
unsigned mID;
public:
compare_id(unsigned i) : mID(i) {}
bool operator()(const Entity* a)
{ return a->ID == mID; }
};
void EntityList::removeID(unsigned ID)
{
vector<Entity*>::reverse_iterator ritr;
ritr = find_if(myEntityList.rbegin(), myEntityList.rend(),
compare_id(ID));
if (ritr != myEntityList.rend()) {
vector<Entity*>::iterator itr = ritr.base();
--itr;
delete *itr;
myEntityList.erase(itr);
}
}
---
If your primary access to the elements are through the IDs, you could
try another container like map<> or multimap<>.
---
Daniel K. O.
_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis.
Instale o discador agora! http://br.acesso.yahoo.com/
|