void foobar(){
int local;
static int value;
class access{
void foo(){
local = 5; /* <-- Error here */
value = 10;
}
}bar;
}
void main(){
foobar();
}
Why doesn't access to local
inside foo()
compile? OTOH I can easily access and modify the static variable value
.
Inside a local class you cannot use/access auto variables from the enclosing scope. You can use only static variables, extern variables, types, enums and functions from the enclosing scope.
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