1.
#ifndef __INFRAY_SINGLETON_H__ #define __INFRAY_SINGLETON_H__ #include <unistd.h> #define PATTERN_SINGLETON_DECLAREY(classname) \ private: \ classname(); \ public: \ static classname * Instance(); \ virtual ~classname(); #define PATTERN_SINGLETON_IMPLEMENTY(classname) \ classname * classname::Instance() \ { \ static classname * _instance = NULL; \ if(NULL == _instance) \ { \ _instance = new classname; \ usleep(10000); \ } \ return _instance; \ } #endif
使用:
在头文件的类中声明
并在C文件中实现
标签:__,SINGLETON,PATTERN,模式,classname,instance,单例,声明,define From: https://www.cnblogs.com/donxiao-999/p/17081585.html