I would like to pass my class method as an argument to a (third-party) function
(listner - that cannot be changed) that accepts a function pointer and a void*
. Following is an example:
#include <functional>
typedef void(*pfnc) (void*);
struct Foo
{
static void static_foo(void*)
{
}
void foo(void*)
{
}
void listner(pfnc f, void* p)
{
f(p);
}
void test()
{
listner(static_foo); // works with static method
auto f = [](void*) {};
listner(f); // works with lambda
std::function<void(void*)> stdf = std::bind(&Foo::foo, this, std::placeholders::_1);
listner(stdf); // does not compile with not static method
}
};
Unfortunately my solution does not compile. What do I have to change?