#include<iostream>
using namespace std;
class Hablee
{
private:
size_t* nYuki; // 有多少个yuki
public:
Hablee() :nYuki(new size_t(1)) {}
Hablee(const Hablee& other) :nYuki(other.nYuki)
{
*nYuki += 1;
}
~Hablee()
{
*nYuki = *nYuki - 1; // 析构一个对象,减掉一个计数
if (*nYuki == 0)
{
delete nYuki;
}
}
void printnYuki()
{
std::cout << "cnt yuki = " << *nYuki << std::endl;
}
};
int main()
{
Hablee hbli;
cout << "print hbli" << endl;
hbli.printnYuki();
cout << endl;
cout << "print hbli2" << endl;
Hablee hbli2;
hbli2.printnYuki();
cout << endl;
cout << "print hbli3" << endl;
Hablee hbli3(hbli);
hbli3.printnYuki();
hbli.printnYuki();
cout << endl;
return 0;
}