一、整体代码
01.cpp
#include <iostream>
using namespace std;
class Singleton
{
public:
static Singleton* GetInstance()
{
if (instacne_ == NULL)
{
instacne_ = new Singleton;
}
return instacne_;
}
~Singleton()
{
cout<<"~Singleton ..."<<endl;
}
//static void Free()
//{
// if (instacne_ != NULL)
// {
// delete instacne_;
// }
//}
class Garbo
{
public:
Garbo(){
cout<<"Garbo Construct"<<endl;
}
~Garbo()
{
cout<<"Garbo Destroy"<<endl;
if (Singleton::instacne_ != NULL)
{
delete instacne_;
}
}
};
private:
Singleton(const Singleton& other);
Singleton& operator=(const Singleto