Hi, I'm a beginner to C++ and am having some trouble with my list. I first define a struct named "bullet' like so:
struct bullet {
bool alive;
bullet()
alive = true;
};
Then, I create a list of objects of type "bullet": list<bullet> bullet_list;
In my program, I frequently add new bullets to the list and delete them. At first, I was using a vector, but then I read that using a list was better for my uses because of how often I create/delete bullets from various positions in the list (I actually did this so frequently that I would get buffer overrun errors, which is why I'm now trying lists).
Anyways, when I was using a vector, I could use the following code to check if the bullet was still "alive":
for (int i=0; i < bullet_list.size(); i++) {
bool isalive = bullet_list[i].alive;
// do stuff
But now that I am using a list, I cannot. I get the following error: Error 1 error C2676: binary '[' : 'std::list<_Ty>' does not define this operator or a conversion to a type acceptable to the predefined operator
What do I have to change in order to make this work?
Thanks in advance.