effective C++条款十五解读
来源:互联网 发布:云端收银软件 编辑:程序博客网 时间:2024/06/05 22:53
在资源管理类中提供对原始资源的访问
当我们用资源管理类来管理对象的时候,很多我们调用的系统API可能需要接受原始的资源参数,这时候我们的资源管理类必须提供对原始资源的访问。
比如shared_ptr就提供了get方法来拿到底层的原始指针。
一般来说,获取原始资源的方法有两个
1.调用get函数获得原始资源。
2.在类中实现类型转换函数。
用一个字体管理类来分别阐述上面两种做法:
class Font{public: explicit Font(FontHandle fh):f(fh){} ~Font(){ releaseFont(f);} FontHandle get() const { return f; }private: FontHandle f;}
class Font{public: explicit Font(FontHandle fh):f(fh){} ~Font(){ releaseFont(f);} operator FontHandle() const { return f; }private: FontHandle f;}
阅读全文
0 0
- effective C++条款十五解读
- effective C++条款二十五解读
- Effective C++ 条款二解读
- effective C++ 条款三 解读
- effective c++ 条款4解读
- effective C++条款五解读
- effective C++ 条款六解读
- effective C++ 条款八解读
- effective C++ 条款九解读
- effective C++ 条款十解读
- effective C++ 条款十一解读
- effective C++ 条款十二解读
- effective C++ 条款十三解读
- effective c++ 条款十四解读
- effective C++ 条款十六解读
- effective C++ 条款十七解读
- effective C++ 条款十八解读
- effective C++条款十九解读
- 【OpenCV3.3】特征值、奇异值分解与图像矩阵重构
- 19muduo_base库源码分析(十)
- 2017CCPC网赛1003
- 【C#学习】lambda表达式
- Filter过滤器的作用和工作原理
- effective C++条款十五解读
- 导入证书burpsuit CA
- jQuery基础知识。
- UVA
- 贪心算法详解
- vmware linux 不能解析dns,http 599 name lookup timed out
- qmake手册——构建常见项目类型
- servlet学习笔记(一)-servlet的创建
- python 变量前的 单下划线 双下划线