![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
智能指针
努力的zjk
这个作者很懒,什么都没留下…
展开
-
shared_ptr探究
boost库下shared_ptr的源码shared_ptr类构造函数拷贝构造函数赋值语句私有成员#include <thread>#include <mutex>template <class T>class SharedPtr{public: SharedPtr(T* ptr = nullptr) : _ptr(ptr) , _pRefCount(new int(1)) , _pMutex(new mutex) {原创 2020-11-17 22:19:26 · 285 阅读 · 0 评论 -
智能指针的初步认识
开辟了内存空间,必定要释放内存空间,如果不释放就会造成内存泄漏,引发安全问题。如果代码量很少的时候,我们会记得释放掉开辟的空间,但是如果代码量过大,我们会忘记开辟的空间,那么就需要智能指针来帮助我们自动释放空间。例如:#include<memory>int main(){ int* tmp = new int[10]; auto_ptr<int> ap(tmp); cout << *ap <<endl; //delete []tmp; re原创 2020-10-22 14:01:15 · 205 阅读 · 0 评论