Singleton.h 405 B

12345678910111213141516171819202122232425
  1. /*
  2. * Copyright 2010, Pier Luigi Fiorini. All rights reserved.
  3. * Distributed under the terms of the MIT License.
  4. */
  5. #ifndef _SINGLETON_H
  6. #define _SINGLETON_H
  7. template<typename T>
  8. class Singleton {
  9. public:
  10. static T* Get()
  11. {
  12. if (!fInstance)
  13. fInstance = new T();
  14. return fInstance;
  15. }
  16. protected:
  17. static T* fInstance;
  18. Singleton() {}
  19. };
  20. #endif // _SINGLETON_H