Get location of element you just pushed into vector C++
Posted
by
Satchmo Brown
on Stack Overflow
See other posts from Stack Overflow
or by Satchmo Brown
Published on 2012-05-30T22:37:45Z
Indexed on
2012/05/30
22:41 UTC
Read the original article
Hit count: 270
I am curious about how pushing back into a vector works. I want a way to push back an element and then be able to add it's location in the vector to a double array serving as a type of map.
Something like this:
// Create a bomb
Bomb b;
b.currentTime = SDL_GetTicks();
b.explodeTime = SDL_GetTicks() + 3000;
b.owner = player;
b.power = 2;
b.x = x;
b.y = y;
bombVec.push_back(b);
bombs[y][x] = THIS_IS_WHAT_I_WANT;
This way when I explode the bomb, I can check the map and then have an ID in the vector to deal with. Every non bomb square will have a -1. Also, just curious. Imagine I have 3 elements in a vector. I delete the second one and then add another. Does the new element go in the same location as the one that was deleted?
Thanks!
© Stack Overflow or respective owner