#include <iostream>
using namespace std;

class Singleton {
private:
    Singleton() {  }
    ~Singleton() { }

    static Singleton* pSingleton;

public:
    static Singleton* GetInstance() {
        if (pSingleton == NULL)    {
            pSingleton = new Singleton();
        }

        return pSingleton;
    }
};

Singleton* Singleton::pSingleton;

int main()
{
    Singleton* p1 = Singleton::GetInstance();
    cout<<hex<<p1<<endl;

    Singleton* p2 = Singleton::GetInstance();
    cout<<hex<<p2<<endl;

    return 0;
}
 posted on 2012-08-20 19:09  晴朗蝈蝈  阅读(78)  评论(0)    收藏  举报