template class Destroyer { public: Destroyer(T* d_=0) : m_otg (d_) { /* empty */ } ~Destroyer() { if ( m_otg ) { delete m_otg; } } void setGuard(T* d_) { m_otg = d_; } private: Destroyer(const Destroyer&); Destroyer& operator=(const Destroyer&); private: T* m_otg; }; template class Singleton { public: static T* getInstance () { if (m_instance == 0) { m_instance = new T; m_destroyer.setGuard (m_instance); } return m_instance; } protected: friend class Destroyer; private: /// Pointer to the object T instance static T* m_instance; static Destroyer m_destroyer; }; class Child : public Singleton < Child > { int dummy; }; template<> Child* Singleton ::m_instance = 0; template<> Destroyer Singleton::m_destroyer = 0; void test(void) { Child *c = Child::getInstance(); }