boost::bind\boost::function
来源:互联网 发布:fit健身软件好用吗 编辑:程序博客网 时间:2024/05/01 12:08
boost::function就是C++中的函数对象
一般的定义方法 : typedef boost::function<void(int ,int)> func; func object;//定义了一个有两个int参数和一个void返回值的函数
在将func类型的函数对象当做参数传递时,需要用boost::bind来将函数打包成function函数对象后传入
比如函数:
void Print(int a ,int b) //void 返回值 + 两个int参数
{
cout<<a<<b<<endl;
}
将这个函数当做参数传递时,要先用bind绑定,boost::bind(Print,_1,_2)这样这个函数就被包装成了一个func类型。_1,_2是两个参数占位符,有多少参数就占多少个
比如
void log(func ob)
{
ob(100 ,1000 ); //调用Print函数
}
log(boost::bind(Print,_1,_2))//传入Print函数
boost::bind返回的是一个boost::function类型
看起来还是很长,其实在将函数当做参数的时候,定义参数类型的时候比不一定需要用function函数生成一个函数类型,直接用template定义一个类型就可以了
这样
template<typename _T>
void log(_T ob)
{
ob(100,1000);
}
这样就少些了很多代码,但是可读性就差了。
0 0
- boost::bind\boost::function
- boost::bind/boost::function
- boost::function和boost::bind
- boost::function 和boost::bind
- boost function bind用法
- boost : ref , bind , function
- boost::function & boost::bind 源码分析
- boost::function boost::bind 简单示例
- 编程模仿boost::function和boost::bind
- 当Boost.Function遇到Boost.Bind
- boost::bind和boost::function使用示例
- boost::function与boost::bind 的使用
- [C++] boost::function boost::bind 与 回调
- boost bind function用法说明
- boost::function/bind 的使用
- 【Boost】以boost::function和boost:bind取代虚函数
- Boost函数对象 boost.bind boost.function Boost.Ref Boost.Lambda
- 在VC6中实现Boost::Bind/Function
- J2EE JAR 包---EJB应用所需要的jar包
- 学习笔记———《EM算法》
- Hadoop权限管理
- OpenCart之商品分类(Category)模块教程
- 简单的生产者消费者模型
- boost::bind\boost::function
- Android的SoundPool
- 通过dblink impdp导入
- Solr3.6.1 在Tomcat6下的环境搭建
- Struts2入门的第一个应用
- [枚举]糖果采购
- 软件测试面试题整理
- RHEL6 DNS服务详解
- 改变按钮获取焦点、点击、失去焦点是的背景