使用boost::bind/std::bind进行封…
来源:互联网 发布:软件被劫持 编辑:程序博客网 时间:2024/05/29 18:54
=====================测试代码======================
#include <iostream>
#include <boost/bind.hpp>
#include<boost/function.hpp>
#include<boost/shared_ptr.hpp>
using namespace std;
class BindArgument
{
public:
BindArgument(int num)
{
this->num = num;
cout << "BindArgument:"<< num<< endl;
}
void foo() const
{
cout << num<< endl;
}
~BindArgument()
{
cout << "~BindArgument:"<< num<< endl;
}
BindArgument(const BindArgument& copy)
{
num = copy.num;
cout << "copy:"<< num<< endl;
}
private:
int num;
};
void testBind0(BindArgument val)
{
val.foo();
}
void testBind1(const BindArgument& val)
{
val.foo();
}
void testBind2(BindArgument* val)
{
val->foo();
}
voidtestBind3(boost::shared_ptr<BindArgument>val)
{
val->foo();
}
int main()
{
{
BindArgument* obj = new BindArgument(0);
boost::function<void (void)>func = boost::bind(&testBind0, *obj);
delete obj;
func();
}
cout <<"====================================="<< endl;
{
BindArgument* obj = new BindArgument(1);
boost::function<void (void)>func = boost::bind(&testBind1, *obj);
delete obj;
func();
}
cout <<"====================================="<< endl;
{
BindArgument* obj = new BindArgument(2);
boost::function<void (void)>func = boost::bind(&testBind2, obj);
delete obj;
func();
}
cout <<"====================================="<< endl;
{
boost::shared_ptr<BindArgument>obj(new BindArgument(3));
boost::function<void (void)>func = boost::bind(&testBind3, obj);
obj.reset();
func();
}
}
=============================测试结果=============================
BindArgument:0
copy:0
copy:0
copy:0
copy:0
~BindArgument:0
~BindArgument:0
copy:0
~BindArgument:0
~BindArgument:0
copy:0
copy:0
copy:0
copy:0
copy:0
copy:0
~BindArgument:0
~BindArgument:0
~BindArgument:0
~BindArgument:0
~BindArgument:0
~BindArgument:0
~BindArgument:0
copy:0
0
~BindArgument:0
~BindArgument:0
=====================================
BindArgument:1
copy:1
copy:1
copy:1
copy:1
~BindArgument:1
~BindArgument:1
copy:1
~BindArgument:1
~BindArgument:1
copy:1
copy:1
copy:1
copy:1
copy:1
copy:1
~BindArgument:1
~BindArgument:1
~BindArgument:1
~BindArgument:1
~BindArgument:1
~BindArgument:1
~BindArgument:1
1
~BindArgument:1
=====================================
BindArgument:2
~BindArgument:2
1133176
=====================================
BindArgument:3
3
~BindArgument:3
0 0
- 使用boost::bind/std::bind进行封…
- std::bind的使用
- std::bind()的使用
- std::bind1st std::bind2nd boost::bind
- BOOST::bind 如何使用
- boost::bind的使用
- boost bind的使用
- boost bind使用资料
- boost bind的使用
- Boost.bind 的使用
- boost::bind的使用
- 使用boost的bind
- Boost::bind使用详解
- 【boost】boost::bind的使用
- C++中std::tr1::function和bind 组件的使用 和 以boost::function和boost:bind取代虚函数
- std::bind
- std::bind
- std::bind
- SQLite批量插入IOS代码示例
- SQLite批量插入Android代码示例
- 对开发日志的一些心得
- 顺藤摸瓜研究应用程序如何监控文件…
- 判断键值对中是否存在某个键
- 使用boost::bind/std::bind进行封…
- Java、IOS、C之间进行RSA密文传输
- 版本号的比较函数
- 在QT的信号和槽中使用自定义类型
- 变量和函数是否应该设置为static
- MYSQL实践心得:table_open_cache…
- DevOp经验谈:服务故障排查的第一…
- DevOp经验谈:直接操作线上数据库…
- 解决Java从MySQL读取大量数据时卡…