C++使用宏定义单例模式

声明宏:

#define PATTERN_SINGLETON_DECLARE(classname)	\
static classname * instance();	\
static CMutex s_singletion_mutex;

实现宏:

#define PATTERN_SINGLETON_IMPLEMENT(classname)	\
CMutex classname::s_singletion_mutex;	\
classname * classname::instance()		\
{												\
	CGuard tmpGuard(s_singletion_mutex);				\
	static classname * _instance = NULL;		\
	if( NULL == _instance)						\
	{											\
		_instance = new classname;				\
	}											\
	return _instance;							\
}


展开阅读全文

没有更多推荐了,返回首页