#include<iostream>
using namespace std;
class singleton
{
public:
static singleton* getpsin()
{
if(psin == NULL)
{
psin = new singleton();
}
return psin;
}
static void relice()
{
if(psin != NULL)
{
delete psin;
}
psin = NULL;
}
private:
singleton()
{cout<<"+++++"<<endl;}
static singleton* psin;
};
singleton* singleton::psin = NULL;
int main()
{
singleton* p = singleton::getpsin();
return 0;
}
C++ 设计一个类,只能生成一个对象
最新推荐文章于 2023-03-20 23:17:39 发布