I have a C language function to be called:
f_api(void(*callback)(int))
and I have a static class method for the callback:
struct A {
static void CallBack(int i) {
A::count = i;
}
static count = 0;
};
I can call the function like this:
f_api(&A::CallBack)
However, I have to change the callback to non-static now, because I have to create multiple A
objects.
But I cannot change the definition of f_api()
.
I tried using a lambda:
f_api([this](int i)->void{this->count = i;})`
But this failed, because I cannot convert a lambda with capture into a simple function pointer.
std::bind()
also cannot do the work, because of the f_api()
definition.
What can I do for this? How can I get a function pointer from a lambda expression? Is there any method to sidestep?