Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

tr1 functional and boost bind and stuff

Name: OP 2011-03-20 19:02

I'm trying to make a 2d game engine in c++. It's nearly done, only I have one problem I can't seem to find a solution to:

I have an engine class that acts as an interface for the engine proper (that is, user->engine-renderer/inputHandler/helper). Now, I want to let the user assign a function to be executed when the specified event happens:

>void addFunc(EventType e, std::tr1::function<void(void)> func);

I am using

>std::tr1::unordered_map<EventType, std::tr1::function<void(void)>> map;

to keep track of those. During my main loop, I check if a key was pressed, and if so, I call:

>map[*unicode value of pressed key*]();

Now: I need to bind member functions, and to be sure nothing weird happens (the more standard way doesn't work anyway), I use the following as a function:

>boost::bind(&class::func_to_bind, &instance_of_class)

where func_to_bind is:

>void func_to_bind(void);

so let's say the first argument of addFunc was '1' (since the second argument is the boost::bind-generated function), whenever '1' is pressed, func_to_bind has to trigger.

Instead I get std::tr1::bad_function_call thrown at me by std::tr1::function<void(void)> when it is called.

QUESTION 1:
Is there an easier way to achieve my goal of letting the engine's user bind a function to a key?

QUESTION 2:
What might cause the problem I am encountering?

Name: Anonymous 2011-03-21 20:35

NIGGER NIGGER(NIGGER){NIGGER NIGGER}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List