class Singleton1
{
private:
static Singleton1* m_pInstance1;//需要的时候才创建,懒汉
//利用static关键字的特性,不属于任何类,整个类只有一个
Singleton1();
public:
static Singleton1* GetInstance1();
static void DestroyInstance1();
};
Singleton1::Singleton1()
{
cout << "创建单例" << endl;
}
Singleton1* Singleton1::GetInstance1()
{
return m_pInstance1;
}
void Singleton1::DestroyInstance1()
{
if (m_pInstance1 != nullptr)
{
delete m_pInstance1;
m_pInstance1 = nullptr;
}
}