shared pointer
#include <string>
#include <fstream>
#include <memory>
#include <cstdio>
class FileDeleter
{
private:
std::string filename;
public:
FileDeleter(const std::string& fn)
:filename(fn){}
void operator()(std::ofstream* fp){
fp->close();
std::remove(filename.c_str());
}
};
int main()
{
std::shared_ptr<std::ofstream> fp(new std::ofstream("tmpfile.txt"),FileDeleter("tmpfile.txt"));
}
shared pointer的更多相关文章
- smart pointer
smart pointer是一种abstract data type,它可以模仿指针的行为,而且额外提供了一系列诸如自己主动内存管理.边界检查等特性,这些特性是为了在保证效率的基础上降低因为对指针的不 ...
- C++2.0新特性(八)——<Smart Pointer(智能指针)之unique_ptr>
一.概念介绍 unique_ptr它是一种在异常发生时可帮助避免资源泄露的smart pointer,实现了独占式拥有的概念,意味着它可确保一个对象和其他相应资源在同一时间只被一个pointer拥有, ...
- boost smart pointer
1. boost::scoped_ptr is a smart pointer that is the sole owner of a dynamically allocated object and ...
- std::shared_ptr(二)
Defined in header <memory> template< class T > class shared_ptr; (since C++11) ...
- The C++ Standard Library --- A Tutorial Reference 读书笔记
5.2 Smart Pointer(智能指针) shared_ptr的aliasing构造函数,接受一个shared pointer和一个raw pointer.它允许你掌握一个事实:某对象拥有另一个 ...
- PCL点云库:对点云进行变换(Using a matrix to transform a point cloud)
点云数据可以用ASCII码的形式存储在PCD文件中(关于该格式的描述可以参考链接:The PCD (Point Cloud Data) file format).为了生成三维点云数据,在excel中用 ...
- 对boost::shared_from_this的进一步封装
对boost::shared_from_this的进一步封装 熟悉异步编程的同学可能会对boost::shared_from_this有所了解.我们在传入回调的时候,通常会想要其带上当前类对象的上下文 ...
- juce 中的WeakReference分析
juce中的WeakReference设计得比较巧妙,巧妙就是使用delete之后就可以通知道WeakReference,原理其实也很间单,其实就是在对象里添加了一个子对象masterReferenc ...
- System V 机制(转)
引言 UNIX 内核管理的进程自主地操作,从而产生更稳定的系统.然而,每个开发人员最终都会遇到这样的情况,即其中一组进程需要与另一组进程通信,也许是为了交换数据或发送命令.这种通信称为进程间通信(In ...
随机推荐
- MySQL数据库的二进制安装、源码编译和基础入门操作
一.MySQL安装 (1)安装方式: 1 .程序包yum安装 优点:安装快,简单 缺点:定死了各个文件的地方,需要修改里边的相关配置文件,很麻烦 2 .二进制格式的程序包:展开至特定路径,并经过简单配 ...
- GNS3
什么是GNS? GNS Graphical Network Simulator Simulator or Emulator? 尽管GNS全拼包含simulator,但实际上是emulator.我们说其 ...
- sqlserver 拼接字符串
SELECT CAST(USER_ID AS VARCHAR) + ',' FROM dbo.AUTH_USER FOR XML PATH('');
- 版本问题---cuda和tensorflow的版本对应关系
cuda和tensorflow的版本有对应关系 https://tensorflow.google.cn/install/source#linux
- 正则表达式匹配IP地址
'''首先分析ip地址的特征:255.255.255.255,前三位的数字处理基本一致 1位: 0-9 \d2位:10-99 [1-9]\d3位:100-19 ...
- JS 自定义组件
经常会用到JS插件,但从未研究过插件的写法 目前主流的写法有多种,各有各的优缺点,下面,我就以最常规的一种写法举例 // plugin.js ;(function(undefined) {//防止出现 ...
- ACM-ICPC 2018 青岛赛区现场赛 D. Magic Multiplication && ZOJ 4061 (思维+构造)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意:定义一个长度为 n 的序列 a1,a2,..,an ...
- 了解 Spring Boot
Spring Boot是什么,解决哪些问题? SpringBoot是伴随着Spring4.0诞生的: 从字面理解,Boot是引导的意思,因此SpringBoot帮助开发者快速搭建Spring框架: S ...
- C# Contract诊断
命名空间 : using System.Diagnostics.Contracts; 属性标记 : [ContractOption(category: "runtime", set ...
- docker harbor 清理释放存储空间
0.harbor界面端清理镜像 1.停止docker harbor docker-compose stop 2.预览运行效果 docker run -it --name gc --rm --volum ...