class Base {
protected:
union {
struct {
bool bBold : 1;
bool bFakeBold : 1;
};
int a;
};
public:
bool isBold() {
return bBold;
}
};
Test类:为什么保护不会保护这个班级的成员?
#include <assert.h>
#include <stdio.h>
int main()
{
Base d;
d.bBold = false;
assert(d.isBold() == false);
d.bBold = true;
assert(d.isBold() == true);
printf("good");
return 0;
}
两个msvc11和g ++编译没有任何错误。
为什么?
看起来还有一个不使用工会的理由。 –
clang 3.2给出了'错误:'bBold'是预期的'Base'的受保护成员。 gcc 4.7.2不抱怨(对于'protected',甚至对'private') – alfC
msvc给出警告[C4201](http://msdn.microsoft.com/en-us/library/c89bw853(v = vs .71).aspx) – spiritwolfform