Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- template<typename T>
- class Singleton
- {
- public:
- Singleton() = delete;
- Singleton(const Singleton<T> &) = delete;
- Singleton<T> & operator =(const Singleton<T> &) = delete;
- ~Singleton() = delete;
- static T * getInstance();
- static bool delInstance();
- private:
- static T *m_Self;
- };
- template<typename T>
- T *Singleton<T>::m_Self = nullptr;
- template<typename T>
- inline T * Singleton<T>::getInstance()
- {
- if (!m_Self)
- {
- m_Self = new T();
- }
- return m_Self;
- }
- template<typename T>
- inline bool Singleton<T>::delInstance()
- {
- if (m_Self)
- {
- delete m_Self;
- m_Self = nullptr;
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement