I can't bind a non-static member function to a callback.
I have to bind the test2
class member function here()
to test1
member callBack
which is a std::function
, but I could not find way to do this. Anyone can suggest me if you have any idea.
Show in code
#include <iostream>
#include <stdint.h>
#include <functional>
using namespace std;
class test1{
public:
typedef std::function<void()> callback_function_t;
callback_function_t callBack;
void setCallback(callback_function_t _callBackfn){
callBack = std::move(_callBackfn);
}
void check(void){
callBack();
}
};
class test2{
public:
void here(){
cout << "safsafsdf" << endl;
}
};
int main(){
test1 t1;
test2 t2;
t1.setCallback(t2.here); // Can't Works
return 0;
}
must be set in test1 callback.