2021-06-16

阅读 31

2022-04-13

template<class T>
    class Singleton
    {
    public:
        Singleton()
        {
            LordAssert(!ms_pSingleton);
            ms_pSingleton = static_cast<T*>(this);
        }

        ~Singleton()
        {
            LordAssert(ms_pSingleton);
            ms_pSingleton = NULL;
        }

    private:
        /** \brief Explicit private copy constructor. This is a forbidden operation.*/
        Singleton(const Singleton<T>&);

        /** \brief Private operator= . This is a forbidden operation. */
        Singleton& operator = (const Singleton<T>&);

    public:
        static T* Instance()
        {
            return ms_pSingleton;
        }

    protected:
        static T* ms_pSingleton;
    };

    template<class T>
    T* Singleton<T>::ms_pSingleton = NULL;

精彩评论(0)

0 0 举报