Sign in to follow this  
Benjamin Heath

Linking problem when iterating through a static list in a class

Recommended Posts

Benjamin Heath    925
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

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