std::bind的用法

 

#include <iostream>
#include <functional>
using namespace std;
 
int TestFunc(int a, char c, float f)
{
    cout << a << endl;
    cout << c << endl;
    cout << f << endl;
 
    return a;
}
 
int main()
{
    auto bindFunc1 = bind(TestFunc, std::placeholders::_1, 'A', 100.1);
    bindFunc1(10);
 
    cout << "=================================\n";
 
    auto bindFunc2 = bind(TestFunc, std::placeholders::_2, std::placeholders::_1, 100.1);
    bindFunc2('B', 10);
 
    cout << "=================================\n";
 
    auto bindFunc3 = bind(TestFunc, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1);   // placeholders代表形参的位置,第二个形参放到第一位,第三个形参放到第二位,第一个形参放到第三位
    bindFunc3(100.1, 30, 'C');
 
    return 0;
}

  

 

posted @ 2022-03-19 20:41  小丑_jk  阅读(56)  评论(0编辑  收藏  举报