// // Created by 29019 on 2019/12/17. // #ifndef GENERAL_SIGNLETON_H #define GENERAL_SIGNLETON_H #include #include using namespace std; template class Singletone { public: static T* Instance(){ if(mInstance.get() == nullptr){ mInstance = std::unique_ptr(new T); } return mInstance.get(); } private: Singletone(){} ~Singletone(){} Singletone &operator=(const Singletone&){} static unique_ptr mInstance; }; template unique_ptr Singletone::mInstance; #define DECLARE_SINGLETON(type) \ friend class unique_ptr ; \ friend class Singletone ; #endif