class Singleton{ public:static Singleton* GetInstance(){if (m_pInstance == nullptr){m_pInstance = new Singleton;}return m_pInstance;} private:Singleton(){}//需要將構造和析構定義成私有的防止外界構造和析構~Singleton(){}static Singleton* m_pInstance;//static所有類共享 };#include "singleton.h"Singleton* Singleton::m_pInstance = nullptr;//static變量必須在類外定義并且定義時初始化
打算復習一下幾個常用的設計模式