我有一门简单的课,比如
class Person {
static const int MALE; // in Person.cpp initialized = 1
static const int FEMALE;//in Person.cpp initialized = 2
};
在公司类(Company.cpp 文件,我有公司类)中,我具有开关功能
switch(x){// x is int passed as parameter to function
case Person::MALE:
//do something
break;
case Person::FEMALE:
//do something
break;
}
但是当我尝试构建时 error C2051: case expression not constant
,如果在上面的 switch 中出现错误,当它是 const 时有什么问题?