Sign in to follow this  

Linking problem when iterating through a static list in a class

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

This topic is 4261 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this