以下代码:
void f3()
{
enum AeF3
{
f3E1 = 1,
f3E2,
f3E3,
};
struct AsF3
{
AeF3 e1:2, e2:2, e3:2;
};
AsF3 inst;
inst.e1 = f3E1;
inst.e2 = f3E2;
inst.e3 = f3E3;
cout << "inst.e1 is " << ((inst.e1 == f3E1) ? "" : "not ") << "equal to f3E1" << endl;
cout << "inst.e2 is " << ((inst.e2 == f3E2) ? "" : "not ") << "equal to f3E2" << endl;
cout << "inst.e3 is " << ((inst.e3 == f3E3) ? "" : "not ") << "equal to f3E3" << endl;
}
生成以下输出:
inst.e1 is equal to f3E1
inst.e2 is not equal to f3E2
inst.e3 is not equal to f3E3
我怎样才能在没有演员表的情况下解决这个错误?
更多描述
e2 & e3 不能保存大于 1 的值,因为它们必须为它们的符号保存一位。我需要一种方法来告诉编译器不要将此位用作符号,而仍将其用作值。我试过了:
enum AeF3 : byte
但这无济于事。不是 -2,而是比较 254,而 2 不等于 -2 也不等于 254。