boost::function使用
来源:互联网 发布:山东省网络信息办公室 编辑:程序博客网 时间:2024/06/07 03:10
boost::function使用
1.全局非静态函数
int f(int a, int b){ return a + b;}int main(){ boost::function<int(int,int)> func; assert(!func); func = f; // 或者 func = &f; if (func) { cout<<func(10,20)<<endl; } func = 0; assert(func.empty());}
2. 成员函数(Style_1)
struct demo_class{ int add(int a,int b) { return a + b; }};int main(){ demo_class sc; boost::function<int(demo_class&,int,int)> func = boost::bind(&demo_class::add,_1,_2,_3); cout<<func(sc,20,20)<<endl;}3. 成员函数(Style_2)
struct demo_class{ int add(int a,int b) { return a + b; }};int main(){ demo_class sc; boost::function<int(int,int)> func = boost::bind(&demo_class::add,&sc,_1,_2); cout<<func(30,20)<<endl;}4. 常量对象实例
struct demo_class{ int operator()(int x)const { return x * x; }};int main(){ demo_class sc; boost::function<int(int)> func = boost::cref(sc);//使用cref包装常量对象的引用,参看demo_class::operator(int x)const cout<<func3(10)<<endl;}5. 非常量对象实例
struct demo_class{ int operator()(int x) { return x * x; }};int main(){ demo_class sc; boost::function<int(int)> func = boost::ref(sc);//使用cref包装对象的引用,参看demo_class::operator(int x) cout<<func3(10)<<endl;}6. 对象实例(Style_2)
struct demo_class{ int operator()(int x) { return x * x; }};int main(){ demo_class sc; boost::function<int(int)> func = sc; // 这里将对象 sc 的一个拷贝 赋值给 func cout<<func3(10)<<endl; // 这里调用不是对象sc. 而是sc的一个拷贝}
0 0
- 使用boost::function错误
- boost::function使用
- boost之function使用
- boost::bind和boost::function使用示例
- boost::function与boost::bind 的使用
- Boost.Function的基本使用
- Boost.Function的基本使用
- Boost.Function的基本使用
- boost::function/bind 的使用
- boost之function的简单使用
- boost之function的简单使用
- Boost库之function的使用
- Boost库之function的使用
- boost库 bind/function的使用
- boost库 bind/function的使用
- boost库 bind/function的使用
- Boost库之function的使用
- boost库 bind/function的使用
- const
- js 日期格式化函数
- 设计模式-12-状态模式
- LeetCode 141 Linked List Cycle
- Syntax error, parameterized types are only available if source level is 1.5
- boost::function使用
- 方法:删除Provisioning Profiles(描述文件)
- 理解NTFS文件系统,自制简易目录浏览器
- 接口的调用与使用
- World Wind Java开发 加载三维模型
- ArcGIS Runtime SDK for iOS(二) ---使用定时器绘制由point组成的polyLine,并显示位置坐标
- Git使用详细教程
- 解析网络视频真实地址
- RossWeatherMap天气地图项目中踩的雷(二):导入Support-v7-appcompact相关问题汇总