Say I have a function foo
:
void foo(void (*ftn)(int x))
{
ftn(5);
}
It needs as a parameter a void
function that accepts an int as a parameter. Consider
void func1(int x) {}
class X {
public:
void func2(int x) {}
};
Now
foo(&func1)
is ok.
But foo(&X::func2)
isn't ok because X::func2
isn't static and needs a context object and its function pointer type is different.
I tried foo(std::bind(&X:func2, this))
from inside X
but that raises a type mismatch too.
What is the right way of doing this?