如下代码会报错:错误:no match for ‘operator&’ (operand types are ‘NameType’ and ‘int’)
必须强转为整形才行:if ((int)(NameType::Btype) & 1);但是感觉这样写起来很不优雅,能不能像类似非c++11的enum那样写:if (NameType::Btype & 1)。
enum class NameType : uint8_t {
Atype = 0,
Btype,
Ctype
};
using namespace std;
int level = 100;
int sub(){
printf("this is sub foo===%llu\n", NameType::Btype);
if ((NameType::Btype) & 1) { //报错:错误:no match for ‘operator&’ (operand types are ‘NameType’ and ‘int’)
cout << 1 << endl;
} else {
cout << 0 << endl;
}
return 0;
}