单例模式

单例模板

#ifndef _SINGLETON_H_

#define _SINGLETON_H_

template<class T>

class CSingleT

{

    public:  static T * Instance()  

     {   

         if (!ms_pObject)  

         {   

             ms_pObject = new T;

         }   

       return ms_pObject;  

     }

     static void Create()  

     {   

         if (!ms_pObject)   

           {  

              ms_pObject = new T;  

           }

     }

 static void Destroy()

 {  

      if (ms_pObject)  

    {  

       delete ms_pObject;   

       ms_pObject = NULL;   

     }  

}

 static T * Get()

 {   

     return ms_pObject;

 }

 static void Reset()

 {  

     Destroy();   

     Create();  

}

protected:  

static T * ms_pObject;

};

template <class T>

T * CSingleT<T>::ms_pObject = NULL;

#endif

原文地址:https://www.cnblogs.com/cci8go/p/3819712.html