int func(int a, int b)
{
return a + b;
}
void func1(int a, int b, int c, int d, int e)
{
cout << "1: " << a << endl;
cout << "2: " << b << endl;
cout << "3: " << c << endl;
cout << "4: " << d << endl;
cout << "5: " << e << endl;
}
void test_10_bind()
{
int a = 1;
int b = 2;
auto f = bind(func, _1, _2);
cout << "bind int func(int a, int b):auto f = bind(func, _1, _2):f(a,b): " << endl;
cout << f(a,b);
int c = 3;
int d = 4;
int e = 5;
auto f1 = bind(func1, a, b, _2, c, _1);
cout << "bind void func1(int a, int b, int c, int d, int e): " << endl;
//参数d对应的f1()中的第一个参数,对应bind函数func1中的第五个参宿
//参数e对应的f1()中的第二个参数,对应bind函数func1中的第四个参数
//相当于调用func1(a, b, e, c, d);
/*
输出为:
1: 1
1: 2
1: 5
1: 3
1: 4
*/
f1(d, e);
}
C++bind小记
最新推荐文章于 2024-09-18 15:28:36 发布