假设一次需要多个比较:
enum usermode
{
active,
standingby,
inactive,
dead,
// many other modes....
};
class A
{
public:
usermode mode;
};
函数继承指向类 A 的指针(ptr 指向 A)
方法一:
if( ptr->mode == active || ptr->mode == standingby || ptr->mode == inactive || ptr->mode == dead ...//etc )
{
//do something
}
方法B:
usermode cmpmode = ptr->mode;
if( cmpmode == active || cmpmode == standingby || cmpmode == inactive || cmpmode == dead ...//etc )
{
//do something
}
这样做是个好习惯吗?