boost库下shared_ptr的源码
shared_ptr类
构造函数
拷贝构造函数
赋值语句
私有成员
boost库里的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)
{
}
~SharedPtr()
{
Release();
}
SharedPtr(const SharedPtr<T>& sp)
: _ptr(sp._ptr