From standard docs Sec 9.8.1,
A class can be declared within a function definition; such a class is called a local class. The name of a local class is local
to its enclosing scope. The local class is in the scope of the enclosing scope, and has the same access to names outside
the function as does the enclosing function. Declarations in a local class can use only type names, static variables,
extern variables and functions, and enumerators from the enclosing scope.
An example from the standard docs itself,
int x;
void f()
{
static int s ;
int x;
extern int g();
struct local {
int g() { return x; } // error: x is auto
int h() { return s; } // OK
int k() { return ::x; } // OK
int l() { return g(); } // OK
};
// ...
}
Hence accessing an auto variable inside a local class is not possible. Either make your local value as static
or a global one, whichever looks appropriate for your design.