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;
staticint s;
struct inner {void f(int i){int a =sizeof(x); / OK, operand of sizeof is an unevaluated operand
x = i; / error: assign to enclose::x
s = i; / OK, assign to enclose::s::x = i; / OK, assign to global x
y = i; / OK, assign to global y}void g(enclose* p, int i){
p->x = i; / OK, assign to enclose::x}};
};
inner* p =0; / error: inner not found — end example]
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 {staticint x;
void f(int i);
};
};
int enclose::inner::x =1;
void enclose::inner::f(int i){/* ... */}class E {class I1; / forward declaration of nested classclass I2;
class I1 {}; / definition of nested class};
class E::I2 {}; / definition of nested class — end example]