I seem to be having a spot of trouble dealing with erasing elements from an STL vector. The vector erase function requires a vector instead of just an index to delete.
In my class I have a member variable as follows...
vector<Character*> units;
The vector gets populated as follows...
for(int i=0; i<NUM_UNITS; i++)
{
Character* tmpchar = new Character;
tmpchar->Load("PlayerModel.bmf", "ZombieTexture.tga", ZOMBIE_UNIT);
units.push_back(tmpchar);
}
Here is where my error is coming from...
//Delete any dead units
for (vector<Character*>::iterator it = units.begin(); it!=units.end(); it++)
{
if(it->GetHealth() <= 0)
{
//Unload the unit
delete &it
units.erase(it);
}
}
The compiler shouts at me in the if statement. I have no idea how to interpret this error message.
error: request for member `GetHealth' in `*(&it)->__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Character**, _Container = std::vector<Character*, std::allocator<Character*> >]()', which is of non-class type `Character*'|
My thinking in the if statement is that the iterator is of type Character* in which case why can I not call the Character member function GetHealth? The GetHealth function is indeed there but I think the message isin't complaining about the function so much as it doesn't think its a Character pointer. Any Help?
Thanks in advance!
"I would rather be in the boat with a drink on the rocks, than in the drink with a boat on the rocks" -Unknown