// I then fill myAnimals with a for loop that reads back perfectly and shows names and health properly.
// e.g. Animal newAnimal(animalsNames[i], 10 + i); // animalsNames is just a string array
// myAnimals.push_back(newAnimal);
AttackAnimals(2);
void AttackAnimals(int dam)
{
for(int i = 0; i < myAnimals.size(); i++)
{
myAnimals[i].SetHealth(dam);
};
for ( vector<Animal>::iterator iter = myAnimals.begin(); iter != myAnimals.end(); /* empty */ )
{
if ( iter->Check4Death() )
{
cout << iter->GetName() << " has died!\n";
iter = myAnimals.erase( iter );
} else {
iter ++;
}
}
};
// the following are the functions from the class
void Animal::SetHealth(int minus)
{
*m_pHealth -= minus;
}
bool Animal::Check4Death()
{
if(*m_pHealth <= 0)
return true;
else
return false;
};
Edited by Ubermeowmix, 26 July 2012 - 11:04 AM.






