00001 00014 #ifndef __SINGLETON__H__ 00015 #define __SINGLETON__H__ 00016 00020 template <typename T> 00021 class Singleton { 00022 public: 00026 static T & Instance() { 00027 // This variant of returning static variable has big advantage. 00028 // You don't have to care about destruction of the holding object 00029 // (if it was using dynamic allocation or it was declared static 00030 // as a private variable). 00031 // Sometimes it's called "Meyer's singleton", according to the author. 00032 static T instance; 00033 return instance; 00034 } 00035 00036 private: 00037 // Protections - not implemented 00038 Singleton(); 00039 ~Singleton(); 00040 Singleton(const Singleton &); 00041 Singleton & operator=(const Singleton &); 00042 }; 00043 00044 #endif /* #ifndef __SINGLETON__H__ */ 00045 00046 /* End of file Singleton.h */