c++ std::bind
来源:互联网 发布:seo网络推广招聘 编辑:程序博客网 时间:2024/05/10 23:37
案例一:
#include "stdafx.h"#include <iostream>#include <functional> using namespace std;void f(int n1, int n2, int n3){ cout << n1 << " " << n2 << " " << n3 << endl;}int main(){ // f的三个参数,全部绑定到值,对newFunc的调用将不需要提供参数 auto newFunc = std::bind(f, 2, 3, 4); newFunc(); getchar(); return 1;}
打印结果:
#include "stdafx.h"#include <iostream>#include <functional> using namespace std;using namespace std::placeholders;void f(int n1, int n2, int n3){ cout << n1 << " " << n2 << " " << n3 << endl;}int ret4(){ cout << "ret4() called" << endl; return 4;}int main() { // f参数都使用占位符绑定, 需要提供至少三个参数 auto mm = std::bind(f, _1, _2, _3); mm(1, 2, 3); // 1 2 3 mm(1, 2, 3, 4, 5); // 1 2 3; 4和5被丢弃 mm(1, 2, 3, ret4()); // ret4() called<cr> 1 2 3; 会调用ret4(), 但是返回的4被丢弃 getchar(); return 1;}
打印结果如下:
FR:海涛高软(hunk Xu)
阅读全文
0 0
- C++-----------------------------------------------------std::bind
- C++_std::bind std::function 高级用法
- std::bind绑定器、std::function、extern C的使用
- std::bind
- std::bind
- std::bind
- std::bind
- std::bind
- std::bind
- std::bind
- std::function std::bind
- std::function std::bind
- 【C/C++】C++11新特性:std::bind
- C++11 学习笔记 std::function和bind绑定器
- C++11 笔记 std::function,bind绑定器和lambda
- std::function 和 std::bind
- lambda, std::function, std::bind
- std::bind std::find 学习
- Expires、Cache-Control、Last-Modified和Etag总结
- cnn的输入输出
- 第14周Map Sum Pairs
- 服务器监控系统Zabbix的media、graphs、templates、macro图解教程(第三章)
- 公众号文章提升转化率的利器,公众号运营
- c++ std::bind
- 教练技术培训系列篇一——执行力
- 【PAT B1032】挖掘机技术哪家强
- RevitAPI之TransactionGroup和Assimilate方法【比目鱼原创】
- 用实例理解复用Mutex和Condition Variable(三)
- 树莓派播放程序Kodi,资源整理
- 方法与数组基础总结(一)
- C#如何连接SQL Server
- 现代操作系统之多处理机系统(下)