c++ 用宏定义一个函数

#define MAX(a,b) ((a)>(b)?(a):(b))

 

要点:变量都用括号括起来,防止出错,结尾不需要;。在实际编程中,不推荐把复杂的函数使用宏,不容易调试。多行用\

 

 

#define CREATE_FUNC_TYPE(__TYPE__,__PARAM__) \
	static __TYPE__* create(__PARAM__ para) \
{ \
	__TYPE__ *pRet = new(std::nothrow) __TYPE__(); \
	if (pRet && pRet->init(para)) \
{ \
	pRet->autorelease(); \
	return pRet; \
} \
	else \
{ \
	delete pRet; \
	pRet = NULL; \
	return NULL; \
} \
}

http://www.waitingfy.com/archives/1766

1766

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.