You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
504 B

#ifndef SINGLETON_H
#define SINGLETON_H
#include <stdlib.h> // atexit
template<typename T>
class Singleton
{
public:
static T& instance()
{
if (value_ == 0)
{
value_ = new T();
}
return *value_;
}
private:
Singleton();
~Singleton();
static void init()
{
value_ = new T();
}
static void destroy()
{
delete value_;
}
private:
static T* value_;
};
template<typename T>
T* Singleton<T>::value_ = NULL;
#endif