C++设计模式-Singleton单例模式

    template <typename T>
    class Singleton
    {
    public:
        template <typename... Args>
        static T* Instance(Args&&... args)
        {
            if ( m_pInstance == NULL )
            {
                m_pInstance = new T(std::forward<Args>(args)...);
            }
            return m_pInstance;
        }

        static T * GetInstance()
        {
            if ( m_pInstance == NULL )
            {

            }
            return m_pInstance;
        }

        static void DestoryInstance()
        {
            delete m_pInstance;
            m_pInstance = NULL;
        }

    private:
        Singleton();
        virtual ~Singleton();
        Singleton(const Singleton&);
        Singleton& operator = (const Singleton &);

        static T *m_pInstance;

    };
    template <typename T>
    T* Singleton<T>::m_pInstance = NULL;

 
 
上一篇:2.2 HOST主桥


下一篇:Mysql插入内容过长(Packet for query is too large)