Hey, I've got a question about general member function pointers. I'm trying to achieve something similar to the following question How to define a general member function pointer
Essentially what I want to be able to do is to register a member function pointer that accepts a generic Event object as its argument with a specific event type (for example, a KeyboardEvent). Then, in my input management class, what I want to be able to do is whenever the user hits a key, I can create a KeyboardEvent object that contains some data about the keypress, and call all of those member function pointers that I registered with the KeyboardEvent type with my KeyboardEvent object as their parameter.
I've been playing around with boost bind and boost function and they seem to enable me to do 95% of what I want to do, the only problem I am trying to store all of the member function pointers in a vector, but they're all of different types so I can't do that. So I bind them into a function object when I first register the method with my event handling system, which expects me to specify all of the arguments at this point in the execution. I don't have to objects at this point though as the objects are generated by some unknown event in the future.
Sorry if none of this makes any sense.
This is not really an answer to your problem, but merely a hint that what you're trying to accomplish already exists.
It seems like you're trying to implement the Observer pattern. You can read about it here. Once you've grasped the Observer pattern, check out the Boost.Signals2 library. A
boost::signal
is like a vector of event handler function pointers, but much more powerful.Here is an example of using Boost::Signals2 for detecting inputted characters. Hope it helps.
(Here's a more direct answer to your boost::function/bind problem, without all the Boost.Signals2 stuff.)
It seems you're not using the _1, _2, etc. placeholders when using boost::bind. This example illustrates how you should use them:
if I understand your question correctly, you can try following
I reread your question, and finally caught member function part. for this you can use functor.