The following builds in VS 2010:
class C1
{
private:
enum E {E_VAL};
static void methC1() {}
public:
class C2
{
public:
class C3
{
public:
void methC3()
{
int a=E_VAL; // this surprised me
methC1(); // and this too
}
};
};
};
int main()
{
C1::C2::C3 obj;
obj.methC3();
}
Is this standard? I saw this other SO post where an answer compares inner classes to friend classes, but a friend of a friend is not a friend, so wondering what standard says.
The standard says (draft n3337, 11.7 [class.access.nest]
):
1 A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to members of a nested class; the usual access rules (Clause 11) shall be obeyed. [...]
And that's pretty much it. C3
has got the same access right as, say, methC1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With