Sign in to follow this  
FoxMulder900

[SOLVED] Linker error - static vector in singleton class

Recommended Posts

Hello, I am working on a basic event handler class, the class is a singleton and I have almost all the basics in place. When I compile I get the following linker error
error LNK2001: unresolved external symbol "private: static class std::vector<class EventListener *,class std::allocator<class EventListener *> > EventHandler::listeners" (?listeners@EventHandler@@0V?$vector@PAVEventListener@@V?$allocator@PAVEventListener@@@std@@@std@@A)
1>C:\Documents and Settings\Matt\Desktop\Ozzmosis3D\Debug\Ozzmosis3D.exe : fatal error LNK1120: 1 unresolved externals
Here is my code:
#include <SDL.h>
#include <vector>

#include "EventListener.h"

using namespace std;

class EventHandler
{
	static vector<EventListener*> listeners;
public:
	static EventHandler* Singleton();
	static void registerListener(EventListener* listener);
	static void handleEvents();
protected:
	EventHandler(){}
	EventHandler& operator= (const EventHandler&);

};
I am unsure of what is causing the error - I tried making the vector non-static however, since this is a singleton class I get more complaints elsewhere. A brief description of what I am trying to accomplish is as follows: I am trying to implement an event handler that stores a list of objects which inherit from my eventListener class. Then when the event handler gets an event, for example a key press, it will simply iterate through the list of listeners and call their appropriate keyPressed functions. Any help or suggestions would be much appreciated! [Edited by - FoxMulder900 on May 8, 2008 9:41:17 PM]

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