No instance of overload function?

Hey, I kepp getting this error when trying to create a new object object and push it onto a vector container. Heres the code:

1
2
3
4
5
6
7
8
9
10
std::vector<Bullet> n_bullets;


void create()
{
	for(int b=0; b<10; b++)
	{
		n_bullets.push_back(new Bullet);
	}
}


Help would be greatly appreciated :)
 
std::vector<Bullet*> n_bullets;
n_bullets is a vector of Bullet while new Bullet returns a Bullet*. You should be fine with using push_back(Bullet());. Then your function would be equivalent to n_bullets.resize(n_bullets.size()+10);.
Ah thanks, using Bullet* worked. So now after creating new Bullet objects, how would I use them? Would it just be something like this?

draw(n_bullets.back());
1
2
for (size_t i = 0; i != n_bullets.size(); ++i)
    draw(*n_bullets[i]);


It all depends on what your draw function takes as a parameter.
I seem to have it working but I dont understand how I would change variables and such. For example if I had an object named bullet I would just say

bullet.getY();

But with this,

*n_bullet[1].getY();

doesn't work as it says its not a class type, but it should be an object of Bullet :S
*n_bullet[1].getY(); is the same as *(n_bullet[1].getY());
This should work better (*n_bullet[1]).getY();. you can also use the arrow syntax which makes it a bit nicer n_bullet[1]->getY();
Last edited on
Woo! Thanks so much guys :)
Topic archived. No new replies allowed.