[class.local] (original) (raw)

11 Classes [class]

11.6 Local class declarations [class.local]

A class can be declared within a function definition; such a class is called a local class.

[Note 1:

A declaration in a local class cannot odr-use ([basic.def.odr]) a local entity from an enclosing scope.

— _end note_]

[Example 1: int x;void f() { static int s;int x;const int N = 5;extern int q();int arr[2];auto [y, z] = arr;struct local { int g() { return x; } int h() { return s; } int k() { return ::x; } int l() { return q(); } int m() { return N; } int* n() { return &N; } int p() { return y; } };}local* p = 0; — _end example_]

An enclosing function has no special access to members of the local class; it obeys the usual access rules ([class.access]).

Member functions of a local class shall be defined within their class definition, if they are defined at all.

A class nested within a local class is a local class.

A member of a local class X shall be declared only in the definition of X or, if the member is a nested class, in the nearest enclosing block scope of X.