Original Post
I'm working on an event handling framework. It won't link. I don't expect it to run, this code is incomplete. The event manager And the line causing linker error: I really don't want to use function pointers. What did I do wrong? [Edited by - thedustbustr on December 20, 2004 2:58:24 AM]
#define evmgr EventManager::GetSingleton()
typedef boost::function<void (Event e)> Handler;
class EventManager : public System, public Singleton<EventManager>
{
private:
std::map<std::string, std::vector<Handler> > handlers;
std::list<Event> events;
public:
void add_handler(std::string type, Handler h);
void handle_event(const Event e);
void handle_event_now(const Event& e); //ignore time delay requests
bool init();
bool tick();
bool exit();
EventManager();
~EventManager();
};
void EventManager::add_handler(std::string type, Handler h)
{
handlers[type].push_back(h); //register handler with handler list
}
void EventManager::handle_event_now(const Event& e)
{
for(std::vector<Handler>::iterator i=handlers[e].begin();
i != handlers[e.type].end(); ++i)
{
(*i)(e); //call the handler, passing the event as an argument
}
}
EventManager::handle_event(const Event e)
{ events.push_back(e); }
bool EventManager::tick()
{
double time=clock.GetTime();
for(std::list<Event>::iterator i=events.begin();
i!=events.end(); )
{
if ((*i).time >= time)
{
handle_event_now((*i));
delete (*i); //fixme is this right
assert(false); //fix iterator
}
else ++i;
}
return true;
}
bool Input::init()
{
Handler on_keypress; //empty function object
evmgr.add_handler("key", on_keypress);
return true;
}
error LNK2019: unresolved external symbol "public: void __thiscall EventManager::add_handler(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class boost::function<void __cdecl(class Event),class std::allocator<void> >)" (?add_handler@EventManager@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$function@$$A6AXVEvent@@@ZV?$allocator@X@std@@@boost@@@Z) referenced in function "public: virtual bool __thiscall Input::init(void)" (?init@Input@@UAE_NXZ)