Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access problem in local class

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.

like image 490
Howard Avatar asked Nov 06 '22 08:11

Howard


1 Answers

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.

like image 76
Prasoon Saurav Avatar answered Nov 09 '22 03:11

Prasoon Saurav