I have a simple for loop:
for (int i = 0; i < c.numparticles; i++)
{
if ( labs((noncollision[i].getypos())) > 5000 )
{
noncollision.erase (noncollision.begin()+i);
}
}
Where noncollision
is a vector of class particle
. In this specific example, any noncollision
which has a ypos
greater than 5000 should be erased. I have been working with a noncollision
size of 6, of which 2 have ypos
much greater than 5000. However, this for loop is only erasing one of them, completely ignoring the other. My suspicion is that because noncollision
is a vector of classes, that this classes is somehow protected, or causes the array function to act differently? Here is my declaration for noncollision
, and for particle
:
vector<particle> noncollision;
class particle{
private:
int xpos;
int ypos;
int xvel;
int yvel;
bool jc; // Has the particle just collided?
public:
etc....
};
Could anyone explain why this is happening, and how to rectify it? Do I somehow need to set up an 'erase function' for the particle
class?