visual studio 2010 - Storing classes in a vector C++ -


i creating game in c++/directx , have came across problem of storing sprites. can create sprite , store in vector, doing 1 sprite works perfectly. but, when go insert sprite, texture property of previous sprite gets deleted. shall include screen shots of breakpointing , code.

the problem suspect object not being placed vector , relying on temporary object used create sprite. here screenshots:

https://www.dropbox.com/s/g5xdlaqf35w6q57/1.png

https://www.dropbox.com/s/xmcyv611nqc27xc/2.png

and code:

// d2world.h class d2world { public:     // functions     vector<d2sprite> spriteslist;     // more stuff  private:     d2sprite *tempsprite;     // other private variables };  // d2world.h // other functions  // new object created re-assigning tempsprite = new d2sprite();  // when sprite completed, add vector spriteslist.push_back(*tempsprite);  // more stuff here 

what don't understand why texture property being affected?

thanks help.

edit: here header code d2sprite class:

class d2sprite { public:     d2sprite(void);     ~d2sprite(void);     void load(lpdirect3dtexture9 tex);     void position(int x, int y);      int x, y, frame, framew, frameh, columns;     float rotation;      d3dxvector3 getposition();      d3dxvector2 scale;     d3dxvector2 center;     d3dxvector2 translation;      lpdirect3dtexture9 texture;      d3dcolor colour; }; 

you creating copy of d2sprite, , lpdirect3dtexture9 seems pointer...

spriteslist.push_back(*tempsprite); 

why creating d2sprite new, , copying them vector, should have

vector<d2sprite*> spriteslist; 

and copy pointer vector

spriteslist.push_back(tempsprite); 

then call delete on items in vector when don't need them anymore.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -