Jump to content
  • Advertisement
Sign in to follow this  
_Camus_

static vector inside a class

This topic is 3339 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

Hi, i want to this: class obj { public: obj(int i){ ID = i; } int ID; static vector<obj*> It; }; And then create objects obj and push all to the vector, some kind of iterator: obj *a = new obj(0); obj *b = new obj(2); obj *c = new obj(1); obj *d = new obj(3); obj::It.push_back(a); All seems to be good, but: error LNK2001: unresolved external symbol "public: static class std::vector<class obj *,class std::allocator<class obj *> > obj::It" (?It@obj@@2V?$vector@PAVobj@@V?$allocator@PAVobj@@@std@@@std@@A) How could it be? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You have to declare obj::It outside of the class:

class obj
{
public:
obj(int i)
{
ID = i;
}

int ID;
static vector<obj*> It;
};

// More than likely in the .cpp file.
vector<obj*> obj::It;


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!