Loading

设计模式之单例模式

class Singelton
{
public:
    static Singelton *getInstance()
    {
        if(m_p == NULL)
        {
            m_p = new Singelton;
        }
        return m_p;
    }
    static void destroyInstance()
    {
        delete m_p;
        m_p = NULL;
    }

private:
    Singelton() {}
    static Singelton *m_p;
};

Singelton *Singelton::m_p = NULL;

int main()
{
    Singelton *p1;
    p1 = Singelton::getInstance();
    Singelton *p2;
    p2 = Singelton::getInstance();
    cout << p1 << "," << p2 << endl;
    P1 = P2 = NULL;
}
posted @ 2020-09-21 09:41  小森林呐  阅读(53)  评论(0编辑  收藏  举报