Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*!
- \file single.h
- \brief A singleton template class. Make sure you use 'friend class Single<Derived>;' so the derived constructor can be private.
- \author ~Ziggy Stardust
- */
- #ifndef __SINGLE_H__
- #define __SINGLE_H__
- #include <assert.h>
- template <class T>
- class Single {
- protected:
- static T* pInstance;
- public:
- /*
- @param - None
- @return - pointer to derived class
- */
- static T* Instance() {
- if(!pInstance) pInstance = new T;
- return pInstance;
- }
- //Frees up instance
- static void DestroyInstance() {
- if(pInstance) delete pInstance;
- pInstance = 0;
- }
- };
- template <class T>
- T* Single<T>::pInstance = 0;
- #endif
Advertisement
Add Comment
Please, Sign In to add comment