Help Bullet C++

I'm writing the Contra Game by Directx9 and c++
please help me about list of bullets

i'm trying below code but it's error: vector intertor incompatible



1
2
3
4
5
6
7
std::vector<Bullet*> bullets
if (mKeyboard->IsKeyPress(DIK_X))
{
	Bullet* toShoot = new Bullet(noneType, _position.x, _position.y, RIGHT);
	toShoot->Init();
	bullets.push_back(toShoot);
}


Update funtion
1
2
3
4
5
6
7
8
9
10
11
  std::vector<Bullet*>::iterator it = bullets.begin();
  while ((it) != bullets.end())
  {
	(*it)->Update(gameTime, c);

	if ((*it)->IsLive() == false)
	{
		bullets.erase(it++);
	}
  }


Render Funtion
1
2
3
4
5
6
7
8
std::vector<Bullet*>::iterator it = bullets.begin();
while (it != bullets.end())
{
	if ((*it)->IsLive())
	{
		(*it++)->Render(gr, cx, cy);
	}
}
Last edited on
i'm trying below code but it's error: vector intertor incompatible
Is it compilation error? If so knowing which line gives you error would certainly help.

1
2
3
4
if ((*it)->IsLive() == false)
{
	bullets.erase(it++);
}
Invalidates it. erase function returns iterator for a reason. Fix:
1
2
3
4
if ((*it)->IsLive() == false)
{
	it = bullets.erase(it);
}
Topic archived. No new replies allowed.