Jump to content
  • Advertisement
Sign in to follow this  
Benjamin Heath

Linking problem when iterating through a static list in a class

This topic is 4541 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 have a class for event handlers that holds a static list of pointers to them. In a static method, I iterate through that list and call each handler. Here is the relevant code:
// excerpt from EventHandler.h
namespace BasicShooter
{
   class EventHandler
   {
   private:
      static std::list<EventHandler*> handlers;
   public:
      static void HandleAll(SDL_Event &event);
   };
}

// excerpt from EventHandler.cpp
void BasicShooter::EventHandler::HandleAll(SDL_Event &event)
{
   std::list<EventHandler*>::iterator it = handlers.begin();
   // loop through and call all handlers
}



This gives me an "unresolved external symbol" error:
EventHandler.obj : error LNK2001: unresolved external symbol "private: static class std::list<class BasicShooter::EventHandler *,class std::allocator<class BasicShooter::EventHandler *> > BasicShooter::EventHandler::handlers" (?handlers@EventHandler@BasicShooter@@0V?$list@PAVEventHandler@BasicShooter@@V?$allocator@PAVEventHandler@BasicShooter@@@std@@@std@@A)
C:\Documents and Settings\bjh\My Documents\Visual Studio 2005\Projects\BasicShooter\Debug\BasicShooter.exe : fatal error LNK1120: 1 unresolved externals

What am I doing wrong? EventHandler::HandleAll should have access to EventHandler::handlers, right?

Share this post


Link to post
Share on other sites
Advertisement
did you forget to put the following in the .cpp?
std::list<EventHandler*> EventHandler::handlers;

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!