标签:
#pragma once
namespace MyGame
{
template<typename T>
class Global
{
public:
static void Create()
{
ASSERT(!s_instance);
s_instance = new T;
}
static void Set(T* obj)
{
ASSERT(!s_instance);
s_instance = obj;
}
static T& Get()
{
ASSERT(s_instance);
return *s_instance;
}
static void Destroy()
{
ASSERT(s_instance);
delete s_instance;
s_instance = 0;
}
private:
Global();
Global(Global&);
Global& operator =(Global&);
static T* s_instance;
};
template<typename T>
T* Global<T>::s_instance = 0;
}
标签:
原文地址:http://www.cnblogs.com/shihui142857/p/4221430.html