[原创]C++通用宏定义

时间:2023-03-08 18:48:21

//单态模式(singletion)

#defube DECLEAR_SINGLETION(ClassName) \

private: \

static ClassName* m_pInstance;

public: \

static ClassName* GetInstance() \

{ \

if ( NULL == m_pInstance ) \

{ \

m_pInstance = new ClassName();

} \

return m_pInstance;

} \

static void Release() \

{ \

delete m_pInstance; \

m_pInstance = NULL; \

} \

//禁止拷贝和赋值对象

#define DISALLOW_COPY_AND_ASSIGN(ClassName) \

private: \

ClassName(const ClassName&); \

void operator=(const ClassName&); \

//多重条件判断

#define BREAK_IF(cond) if(cond) break

#define BREAK_IF_NOT(cond) if(!cond) break