Get location of element you just pushed into vector C++
- by Satchmo Brown
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!