jeudi 27 juillet 2017

How to get a function pointer from lambda expressions or so?

I have a function call

f_api(void(*callback)(int))

and now I have a static class method:

struct A {
    static void SetCallBack(int i) {
        A::count = i;
    }
    static count = 0;
};

so I can call a C language API function f_api(&A::CallBack)

However I have to change the static function into member function now cause I have to create multi-As.

but I cannot change f_api definition.

I try: f_api([this](int i)->void{this->count = i;}) failed cause 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 now? How can I get a function pointer from lambda expressions?

Aucun commentaire:

Enregistrer un commentaire