The following sample code compiles just fine in Visual C++:
class Test {
private:
struct {
struct {
int privateData;
};
};
};
int main(int, char **)
{
Test test;
test.privateData = 0;
return 0;
}
But why? I'd expect a compiler error because the privateData member should be inaccessible to the function main, since it's supposed to be private like its container's container.
I know that nameless structs are not part of official C++, but this design is asinine.
By the way I've also tried to change private into protected and struct into union: it looks like the compiler refuses to honor access modifiers on anonymous structs and unions that are nested inside another anonymous struct or union.
Can someone explain this feature?