shared_ptr做资源删除器
2015-07-23 15:13
99 查看
struct dialog_t
{
void fun(){
cout << "fun" << endl;
}
};
template<class T>
struct deleter_t
{
void operator () (T* t) const
{
if (t!= NULL)
{
cout << "delte" << endl;
delete t;
t = NULL;
}
}
};
int main()
{
{
auto const p = boost::shared_ptr<dialog_t>(new dialog_t, deleter_t<dialog_t>{});
p->fun();
}
getchar();
return 0;
}
利用shared_ptr管理资源
高级用法
void any_func(void *p)
{
cout << "some sth" << endl;
}
boost::shared_ptr<void> A_ptr((void*)0, any_func);
离开作用域调用 any_func。
{
void fun(){
cout << "fun" << endl;
}
};
template<class T>
struct deleter_t
{
void operator () (T* t) const
{
if (t!= NULL)
{
cout << "delte" << endl;
delete t;
t = NULL;
}
}
};
int main()
{
{
auto const p = boost::shared_ptr<dialog_t>(new dialog_t, deleter_t<dialog_t>{});
p->fun();
}
getchar();
return 0;
}
利用shared_ptr管理资源
高级用法
void any_func(void *p)
{
cout << "some sth" << endl;
}
boost::shared_ptr<void> A_ptr((void*)0, any_func);
离开作用域调用 any_func。
相关文章推荐
- Calculates The Numbers
- RTMFP协议& RTMP
- McAfee EPO3.61更改系统管理员密码后EPO服务启动失败,控制台无法登陆
- Java 基础笔记(一)
- seo优化必须知道的robots.txt写法
- MSSQL 排序函数 ROW_NUMBER() RANK() DENSE_RANK() NTILE()
- Window 下 VFW 视频采集与显示
- 在VS中让一个JS文件智能提示另一个JS文件中的成员
- java装饰者模式
- 网站发布
- 数据库事务正确执行的四个基本要素
- Activity的生命周期
- Node.js前端自动化工具:gulp
- C++ List的用法(整理)
- Vmstst
- OS X 10.10 编译APUE Third Edition 源码
- MySQL使用经验总结
- Leancloud-数据存储功能入门
- SVN插件
- PowerShell 管理VMWare