Jump to content
  • Advertisement
Sign in to follow this  

vectors vectors vectors list or map?

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a hard time trying to truly grasp vectors, list, and maps I have plenty of books, and online links for referencing, and I know what they do. I'm just having a hard time implementing it in my game. I have an Entity class that has a vector and a vector iterator
 //Our Entity List 
	 static vector<Entity*>     EntityList;
	 static vector<Entity*>::iterator EntityList_Interator;

Then I have as an object
//Global vars for our game!
static const int num_rows = 6;
static const int num_cols = 5;
static const int num_blkz = num_rows * num_cols;

//awards scene
static const int num_awardz = 5;
static const string awardz_directory[5] = {"images/5000_blur.png","images/10000_blur.png","images/blue_level_blur.png",
static const int awdz_blk_size = 25;

Entity Blockz[num_blkz];
Entity Awardz[5];

I have it created this way because when I change it to map or list or whatever I choose to decide to change it to I'll be able to create multiple objects of different multiple objects and add them to a single sprite_list that will let me know what is on, off of the screen what to push and pop in the list to render, etc... SO for the most part I think I'm designing it correctly. However I don't know how to delete the i'th object in the list using the iterator or without using it in the Blockz.EntityList Can someone please help?

Share this post

Link to post
Share on other sites
I was using erase(); but I didn't know how to use the iterator with it.

Like Do I need to call the iterator through the Blockz or by Entity::EntityList_Iterator by itself?

I was doing all sorts of things a noob would be doing when they don't know how to properly initialize and utilize what they're trying to use and like always I failed.

Share this post

Link to post
Share on other sites
Here's an example usage:

class Obj {
Obj(int num):num(num) {}

int getNum() { return num; }

int num;

void func() {
list<Obj*> myList;
myList.push_back(new Obj(0));
myList.push_back(new Obj(1));
myList.push_back(new Obj(2));

// Remove all Objs with num == 1
list<Obj*>::it = myList.begin();
while (it != myList.end()) {
if (it->getNum() == 1)
// erase() returns the iterator to the element after the one
// it removes, so we don't increment it in this case
it = myList.erase(it);

This is just to show how to use erase(). For the above, you would usually do something like this:

bool pred(const Obj *obj) {
return obj->getNum() == 1;


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!