Ok, I'm working on a game with several guns that shoot bullets. Each gun class has a dynamic array of bullet objects (I know it should be a linked list) which is resized each time a new bullet is created with this function:
Code:
void gun_t::addbullet(float setx, float sety, float setth) {
int i;
bullet_t *temp = new bullet_t[numbullets];
for (i = 0; i < numbullets; ++i)
temp[i] = bullet[i];
delete [] bullet;
++numbullets;
bullet = new bullet_t[numbullets];
for (i = 0; i < numbullets; ++i)
bullet[i] = temp[i];
bullet[numbullets-1].set(setx,sety,setth);
delete [] temp;
}
So I set up the call to this function like this:
Code:
int temp = numbullets;
addbullet(x,y,th);
if (temp == numbullets) error("what?");
This error message shouldn't be displayed, but it is. Does anybody know why this is happening?