vector <bunny>bunnies;
for (int aa = 0;aa<8;aa++)
{
bunnies.push_back(bunny(0,0)) ; //push back a default constructed bunny.
bunny &workingBunny = bunnies.back() ;//i have lost track of how to use //reference like this
workingBunny.setname(namelist()) ;
workingBunny.setsex(definesex()) ;
workingBunny.setposy(getrand());
workingBunny.setposx(getrand());
workingBunny.setage();
brdray [workingBunny.getposx()][workingBunny.getposy()] = (workingBunny.getsex());
}
getboard();
while (1)//this poor practice is temporary
{
system ("pause");
for (int cc=0;cc<bunnies.size();cc++)
{
bunnies[cc].getolder();
bunnies[cc].hopabout();
bunnies[cc].de_edge(brdray);
brdray [(bunnies[cc].getposx())][(bunnies[cc].getposy())] = bunnies[cc].getsex();
if (bunnies[cc].getage()==15)
{
//i tried 'bunnies.erase(bunnies[cc])', i think i lost rack on how this //code works too
}
}
erase takes an iterator as argument. To convert the index to an iterator you can add the index and the iterator to the first element in the vector. bunnies.erase(bunnies.begin() + cc);
This will make all the bunnies that is stored after the erased element to be moved one step so that their index is reduced by one. If you go on and do cc++ you will miss one bunny so you probably only want to do cc++ if a bunny was not erased.