C++的宏函数单例模式
C++的宏函数单例模式
#define DECLARE_SINGLETON( class_name ) \
public: \
static class_name * instance() \
{ if ( 0 == _object ){ _object = new class_name; } return _object; } \
static void uninit_object() \
{ if ( 0 != _object ){ delete _object; _object = 0; } } \
static void init_object() \
{ uninit_object(); } \
private: \
static class_name * _object; \
#define IMPLEMENT_SINGLETON( class_name ) \
class_name * class_name::_object = 0;