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