27 lines
443 B
C++
27 lines
443 B
C++
#ifndef ___SINGLETON_H__
|
|
#define ___SINGLETON_H__
|
|
|
|
#include <memory>
|
|
|
|
template <typename T>
|
|
class Singleton
|
|
{
|
|
private:
|
|
static std::auto_ptr<T> instance;
|
|
|
|
Singleton(const Singleton& rval){}
|
|
public:
|
|
Singleton(){}
|
|
virtual ~Singleton(){}
|
|
static T *me()
|
|
{
|
|
if (!instance.get())
|
|
instance.reset(new T());
|
|
return instance.get();
|
|
}
|
|
};
|
|
|
|
template <class T>
|
|
std::auto_ptr<T> Singleton<T>::instance;
|
|
|
|
#endif // ___SINGLETON_H__
|