智能指针2--ScopedPtr
来源:互联网 发布:linux查看系统字体设置 编辑:程序博客网 时间:2024/05/20 13:04
ScopedPtr:
1.将拷贝构造和赋值运算符重载设为protected类型。
2.定义构造函数和赋值运算符重载函数。
#pragma oncetemplate<class T>class ScopedPtr{public:ScopedPtr() //无参:_ptr(NULL){}ScopedPtr(T* ptr) :_ptr(ptr){}~ScopedPtr(){if (_ptr){delete _ptr;_ptr = NULL;}}T* operator* (){return *_ptr;}T& operator->(){return _ptr;}protected://定义为保护类,不让外界定义和使用。ScopedPtr(const ScopedPtr<T>& sp);ScopedPtr& operator=(const ScopedPtr<T>& sp);protected:T* _ptr;};void TestScopPtr(){ScopedPtr<int> sp1(new int(1));//ScopedPtr<int> sp2(sp1);}
1 0
- 智能指针2--ScopedPtr
- 智能指针ScopedPtr
- 智能指针之scopedptr
- 智能指针----ScopedPtr和ScopedPtrArray
- 智能指针 AutoPtr ScopedPtr SharedPtr
- 智能指针AutoPtr,ScopedPtr的模拟实现
- 智能指针(模拟实现AutoPtr、ScopedPtr、SharedPtr)
- 智能指针—AutoPtr,ScopedPtr,SharedPtr的模拟实现
- ScopedPtr
- 智能指针2
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 56. Merge Intervals【H】【67】
- javascript中的this
- POJ 2367 Genealogical tree【拓扑排序】
- spark中join和group操作
- LTE Quick Reference, USIM Parameters
- 智能指针2--ScopedPtr
- LeetCode Merge Two Sorted Lists
- java创建文件和目录
- iOS使用自定义字体
- java中equals和==的区别
- 常用算法文章收集
- 欢迎使用CSDN-markdown编辑器
- Codevs 4768 跳石头 NOIP2015 DAY2 T1
- leetcode 88. Merge Sorted Array