C++bind小记

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);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值