/************************************
Author: RobertBaker
Version: 1.0
Comments: 用于单例模式的类声明宏
************************************/
#ifndef CsMacro_H
#define CsMacro_H
#include <stdlib.h>
#define DECLARE_SINGLE(CLASSNAME) public: static CLASSNAME * GetSingle() { if (m_pSingle == NULL) { m_pSingle = new CLASSNAME; atexit(CloseSingle); } return m_pSingle; } static BOOL IsCreated() { return m_pSingle != NULL; } static void CloseSingle() { if (m_pSingle == NULL) { return; } delete m_pSingle; m_pSingle = NULL; } private: static CLASSNAME *m_pSingle;
#define IMPLEMENT_SINGLE(CLASSNAME) CLASSNAME *CLASSNAME::m_pSingle = NULL;
#endif
注: 对于模态对话框不适用