#pragma once template class Singleton { protected: Singleton() { } virtual ~Singleton() { m_pSelf = NULL; } public: static T* Instance(); void FreeInstance(); private: static T* m_pSelf; }; template T* Singleton::m_pSelf = NULL; template T* Singleton::Instance () { if (NULL == m_pSelf) m_pSelf = new T; return m_pSelf; } template void Singleton::FreeInstance() { delete this; }