#include
#include
void func1(){
std::cout<<"this is func1"< f1 = func1;
//调用
f1();
std::function f2 = func2;
//调用
f2(10, 20);
//绑定类静态成员函数
std::function fa = A::funcA;
//调用
fa();
system("pause");
return 0;
}
this is func1
10 + 20 = 30
this is funcA
请按任意键继续. . .
#include
#include
void func1(){
std::cout<<"this is func1"< this is func1
10 + 20 = 30
11 + 90 = 101
请按任意键继续. . .
#include
#include
class A{
public:
void func(int x, int y){
std::cout << "x = "<< x <<", y = "<< y << std::endl;
}
int a;
};
int main(){
A objA;
//绑定成员函数
std::function fa = std::bind(&A::func, &objA, std::placeholders::_1, std::placeholders::_2);
//调用
fa(11, 22);
//绑定成员变量
std::function f2 = std::bind(&A::a, &objA);
f2() = 1234;
std::cout<<"objA a = "<< objA.a << std::endl;
system("pause");
return 0;
}
x = 11, y = 22
objA a = 1234
请按任意键继续. . .