Hey Everyone!
So I can't figure out how to erase an Object from a vector. In java its just Vector.Remove(int element#) but in C++ its iterators and some other wierd stuff. I've spent the last two hours trying to look it up and read on it and everytime by game crashes anyway. Here take a look.
-------------------------------------------------
while ( vhBIt != vhBullet.end() )
{
hBullet &hB = *vhBIt;
hB.hBulletMove();
if (hB.isOutOfBounds()){
dbText(350,20,"Outofbounds");
vhBIt = vhBullet.erase(vhBIt);
}
else
{
vhBIt++;
}
}
------------------------------------------------------
vhBIt is my iterator
vhBullet is my vector for hBullet class
hBullet is my class for bullets. it creates and moves the 3d spheres
hB is the object from hBullet class
So this
while loop keeps going until it goes through the whole vector and each iteration, it moves my bullet, and then checks if its out of bounds. If so, it should delete it. As soon as I go into the while loop the game crashes.
I have also tried this, but also to no luck:
-----------------------------------------------------------
for( int i = 0; i<vhBullet.size() ; i++,vhBIt++ ) {
vhBullet[i].hBulletMove();
if (vhBullet[i].isOutOfBounds()){
dbText(350,20,"Outofbounds");
vhBullet.erase(vhBIt);
}
}
-----------------------------------------------------------
Any advice?
Let me know if any more code/info needed.
Thanks, I really appreciate the help!