bind函数可以将既有函数的参数绑定起来,从而生成一个函数对象:
#include#include using namespace std; void func1(int d) { cout<<__func__<<" "< 如果函数有多个参数,可以只绑定部分参数,然后通过placeholders::_1标示调用函数对象时的参数占位符:
#include#include using namespace std; void func1(int d1, int d2) { cout<<__func__<<" "< 通过bind还可以绑定类的成员函数:
#include#include using namespace std; class A{ public: void f(int d1, int d2) { cout<<__func__<<" "< 需要说明的是:
1.对于绑定的参数(上例中的p)是传值的方式绑定
2.对于placeholders是以传引用的榜示绑定
3.如果需要对绑定的参数以传引用的方式绑定,可以通过ref实现
#include#include using namespace std; void fun(int& d1, int& d2, int& d3) { d1 = 1; d2 = 2; d3 = 3; cout<<__func__<<" "<



