使用引用计数实现最简单的智能指针2
使用模板技术完善智能指针,将引用计数封装到类中
#include
#include
using namespace std;
template
class CSmartPtr;
template
class CRefCount
{
public:
friend class CSmartPtr
CRefCount(T *stu)
{
m_stu = stu;
++m_count;
}
~CRefCount()
{
delete m_stu;
m_stu = nullptr;
m_count = 0;
}
int release(void)
{
if (--m_count == 0)
{
cout << "m_count =" << m_count << endl;
共有 0 条评论