//智能指针完整程序
#include<iostream>
using namespace std;
class auto_p
{
class node
{
public:
int count = 0;
int *head = nullptr;
};
node *p = nullptr;
public:
auto_p() = default;
auto_p(int *data)
{
if(p)
{
p->count --;
if(0 ==p->count)
{
delete p->head;
delete p;
}
}
else
{
p = new node();
p->head = data;
p->count ++;
}
}
auto_p(const auto_p &ap)
{
if(p)
{
p->count--;
if(0 ==p->count)
{
delete p->head;
delete p;
}
else
{
p = ap.p;
if(p)
{
p->count++;
}
}
}
else
{
p = ap.p;
if(p)
{
p->count++;
}
}
}
~auto_p()
{
if(p)
{
p->count--;
if(0 == p->count)
{
delete p->head;
delete p;
}
}
}
}
阅读(221) | 评论(0) | 转发(0) |