mygui并没有使用Singleton 而是在每个需要单件的;类里面加入了
MYGUI_INSTANCE_HEADER 和 MYGUI_INSTANCE_IMPLEMENT
#define MYGUI_INSTANCE_HEADER(type) /
private: /
static type* msInstance; /
bool mIsInitialise; /
public: /
type();/
~type();/
static type& getInstance(); /
static type* getInstancePtr();
#define MYGUI_INSTANCE_IMPLEMENT(type) /
const std::string INSTANCE_TYPE_NAME(#type); /
type* type::msInstance = nullptr; /
type* type::getInstancePtr() { return msInstance; } /
type& type::getInstance() { MYGUI_ASSERT(0 != msInstance, "instance " << INSTANCE_TYPE_NAME << " was not created"); return (*msInstance); } /
type::type() : mIsInitialise(false) { MYGUI_ASSERT(0 == msInstance, "instance " << INSTANCE_TYPE_NAME << " is exsist"); msInstance = this; } /
type::~type() { msInstance = nullptr; }
因为他的单件类本身不再需要写构造和析构函数