Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

revearz

Link errors when using static std::list

This topic is 5174 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''m getting link errors when I''m using a static std::list as a member variable in my class. Completely stumped .. Example: class CTest { public: CTest () { }; ~CTest() { }; static std::vector list; }; static CTest test; int main( ) { test.list.push_back( 1 ); } I get the following link error: "error LNK2001: unresolved external symbol "public: static class std::vector > CTest::list" (?list@CTest@@2V?$vector@HV?$allocator@H@std@@@std@@A)" It links fine when I remove the static declaration in front of the std::vector though. Anyone have a clue? Thanks

Share this post


Link to post
Share on other sites
Advertisement
A static class variable must not only be declared; it must also be defined in a source file. Watch:


// MyClass.h


class MyClass
{
static int i;
};


// MyClass.cpp

int MyClass::i;



"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I see ... thanks for the help. Greatly appreciated.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!