I have a player class which looks like this (stripped down to what is needed for this problem):
class Player { public: Player(); ~Player(); void kill(); void death(); void reset(); }; The kill(), death(), and reset() functions look like this:
void Player::kill() { void (*dPtr)() = &death; Game::idle(dPtr, 48); } void Player::death() { reset(); } void Player::reset() { //resets } The idle function is a static memeber function of Game, which takes a function pointer and an integer n, and calls the function after n tick. Here is the function, the implementation shouldn't matter:
class Game { static void idle(void (*)(), int); }; This code gives me the error:
ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&Player::death' [-fpermissive] So I change the line from
void (*dPtr)() = &death; to
void (Player::*dPtr)() = &Player::death; to solve that issue. But then my call to the idle function is incorrect, as it takes a regular function pointer, and I am passing in a member function pointer, and thus gives me the error:
no matching function for call to 'Game::idle(void (Player::*&)(), int)' So my question is: How can I pass the member function pointer Player::*dPtr into the idle function, which takes a void (*)() as an argument?
Or is there another way I can solve my previous error which forbids me from taking the address of an unqualified member function to form a pointer to a member function?
boost::bindandboost::function.std::bind(), no need for boost in the current standard.std::bindis not assignment-compatible withvoid (*)().static void idle(void (*)(), int);needs to be changed. What's the problem?idle?