Hello all again.
I've come across a rather annoying problem and I know it's because I'm misunderstanding something. I just can't find anything relevant anywhere on Google and the documentation for these two tr1:: objects is severely lacking.
Anyway, I use the Microsoft flavors of compilers. I've been working with a simple callback mechanism using tr1::function/tr1::bind and it's been working [mostly] well. The issue now is when it gets compiled on the mac with GCC/LLVM (although it would probably show the same problem on any other system with GCC).
The error that's popping up is this:
The specific line of code it's referencing is this one:Code:c++/4.2.1/tr1/functional_iterate.h:197: error: cannot apply member pointer '((const std::tr1::_Mem_fn<void (StateManager::*)(Event&)>*)this)->std::tr1::_Mem_fn<void (StateManager::*)(Event&)>::__pmf' to '* __ptr', which is of non-class type 'StateManager*'
The following is the code in context (forgive me for the length):Code:eventHandler.register_callback(EVENT_TYPE_1, std::tr1::bind(&StateManager::handleEvent, &stateManager, std::tr1::placeholders::_1));
Breaking down the error, I'm reading it as "Can't assign member pointer '_pmf' to '* _ptr', a pointer to a StateManager, the pointer not being a class". Confusing, I'm sure, but what's the problem here? Is this something I'm misunderstanding or is this a bug in GCC's implementation of tr1::bind? I'm hesitent to believe that though. How can I resolve this?Code:enum EventType { EVENT_TYPE_1, EVENT_TYPE_2 }; struct Event { int value1; int value2; EventType type; }; class EventHandler { public: typedef std::tr1::function<void(Event& event)> Callback; EventHandler() {} void register_callback(EventType type, Callback callback) { mCallbackMap.insert(pair<EventType, Callback>(type, callback)); } private: typedef std::multimap<EventType, Callback> CallbackMap; CallbackMap mCallbackMap; }; class MyClass { public: go() { EventHandler eventHandler; eventHandler.register_callback(EVENT_TYPE_1, std::tr1::bind(&StateManager::handleEvent, &stateManager, std::tr1::placeholders::_1)); } private: StateManager stateManager; };



LinkBack URL
About LinkBacks


