编程语言
首页 > 编程语言> > Effective c++条款2:尽量用const,enum,inline替换#define

Effective c++条款2:尽量用const,enum,inline替换#define

作者:互联网

#define ASPECT_RATIO 1.653
class GamePlayer
{
private:
    static const int Num = 5;	//声明式
    int scores[Num];
}
#define CALL_WITH_MAX(a,b) f((a) > (b) ? (a) : (b))
int a = 5,b = 0;
//此时,a的调用次数取决于被拿来和谁比较
CALL_WITH_MAX( ++a, b );	//a累加两次
CALL_WITH_MAX( ++a, b + 10 );	//a累加一次

标签:const,常量,Effective,int,enum,Num,define
来源: https://www.cnblogs.com/chenglixue/p/16387424.html