[class.nest] (original) (raw)

11 Classes [class]

11.4 Class members [class.mem]

11.4.12 Nested class declarations [class.nest]

A class can be declared within another class.

A class declared within another is called a nested class.

[Note 1:

See [expr.prim.id] for restrictions on the use of non-static data members and non-static member functions.

— _end note_]

[Example 1: int x;int y;struct enclose { int x;static int s;struct inner { void f(int i) { int a = sizeof(x); x = i; s = i; ::x = i; y = i; } void g(enclose* p, int i) { p->x = i; } };}; inner* p = 0; — _end example_]

[Note 2:

Nested classes can be defined either in the enclosing class or in an enclosing namespace; member functions and static data members of a nested class can be defined either in the nested class or in an enclosing namespace scope.

[Example 2: struct enclose { struct inner { static int x;void f(int i);};};int enclose::inner::x = 1;void enclose::inner::f(int i) { } class E { class I1; class I2;class I1 { }; };class E::I2 { }; — _end example_]

— _end note_]

A friend function ([class.friend]) defined within a nested class has no special access rights to members of an enclosing class.