Duplicate entries in a vector

So, this is similar to the last question. I'm parsing a file into a vector, but whenever I add a new item every other entry becomes a copy of it. When I formerly used arrays, I had no problem. Here is the function, sorry that it is a little verbose but I'm not sure where it might be failing. I'm assuming it has something to do with how the references are being created, but I'm not sure how to fix it and why it worked with arrays and not vectors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
vector<Animation*> Fileio::buildAnimDB(){

        //vector being parsed to
	vector<Animation*> animdb;

        //counter variable
	int pos = 0;

        //file being parsed from
	ifstream anfile("animation.txt", ios::in);

        //checking for end of file
	char name[ANIMATION_NAME_MAX];
	while(anfile.getline(name, ANIMATION_NAME_MAX, '`')){

                //fields to be parsed
		ALLEGRO_BITMAP	*sheet = NULL;
		int				frames = 0;
		int				rate = 0;
		int				loop = 0;
		int				ID;

                //parsing fields
		anfile >> frames;
		anfile >> rate;
		anfile >> loop;
		anfile >> ID;

		//getting rid of erroneous whitespace that shows up after first iteration
		if(pos>0)
			for(int i = 0; i < ANIMATION_NAME_MAX - 1; i++)
				name[i] = name[i+1];

                //this is probably where it's failing
		animdb.push_back(&Animation(al_load_bitmap(name), frames, rate, loop, ID));

		pos++;
	}
	return animdb;
}


When the function finishes, every entry is a reference to the same Animation object.
It would help to know what "Animation" is, but in general, barring any special complications, line 4 should have been
vector<Animation> animdb;
and the line 35
animdb.push_back(Animation(al_load_bitmap(name), frames, rate, loop, ID));
or
animdb.emplace_back(al_load_bitmap(name), frames, rate, loop, ID);
if supported by your compiler
Topic archived. No new replies allowed.