C++11中bind的用法
来源:互联网 发布:中南大学怎么样 知乎 编辑:程序博客网 时间:2024/06/15 02:33
bind可以将函数绑定成另一个可调用的函数对象,可以改变原来函数的传参方式。所以可以把bind看成一个函数的适配器。
#include <functional>#include <iostream>#include <string>using namespace std;int sum(int a, int b, int c){ return a + b + c;}class A{public: void print(string s) { cout << s << endl; } static void func() { cout << "static func" << endl; } int operator()(int a, int b) const { return a + b; }};int main(){ // 绑定普通函数 auto sum2 = bind(sum, 100, placeholders::_1, placeholders::_2); cout << sum2(2,3) << endl; // 绑定类成员函数 A a; auto print2 = bind(&A::print, a, placeholders::_1); print2("good"); // 绑定类静态函数 auto func = bind(&A::func); func(); // 绑定重载operator函数 auto opr = bind(&A::operator(), a, 1, 2); cout << opr() << endl; getchar(); return 0;}
0 0
- [C++] C++11 bind 的用法
- C++11中bind的用法
- C++:boost::bind的一些用法
- C++11 中std::function和std::bind的用法
- C++11 中std::function和std::bind的用法
- c++11-bind的用法
- c++11-bind的用法
- boost库中bind的用法
- !!js中call、apply、bind的用法
- js中call、apply、bind的用法
- 【Boost】boost库中bind的用法
- jquery中unbind和bind的用法
- C++11 std::bind的用法(转)
- prototype的bind用法
- bind的用法
- bind()的用法
- Bind和Eval的不同用法 (asp.net C#)
- Bind和Eval的不同用法 (asp.net C#)
- Sicily 1955/2612. Fort
- NOIP2002 均分纸牌
- Sicily 2611. Da Vinci Code
- 【转】Linux_lsof追踪进程或用户恢复删除文件
- Android开发-四大组件之服务、广播
- C++11中bind的用法
- LeetCode - Trap Rain Water
- Sicily 2610/1897. Chutter and Ladder
- 编译Sanbox
- ARM裸机编程系列---UART
- Sicily 2609/1954. Bracket Expression
- zendstudio 12 配置 xdebug 开发 thinkphp
- Sicily 1898. Tree
- Swift语法基础:17 - Swift的For循环, While, Do-While, If, Switch