This code is in error:
void functionA (){
int varA;
functionB();
}
void functionB(){
varA = 2; ///???
}
This code is an error because, obviously, inside of functionB, "varA" has not been defined and I am referencing an undeclared variable.
My question is, given the scoping/hierarchy of these two functions, is there a way to change functionA's varA via code inside of functionB (and then calling functionB inside of functionA)?
I know you can do something similar with classes by passing the current class instance as a parameter into a function with the "this" keyword. This way, you can change local class variables via a function even if the function is globally defined. Can something similar be done with nested functions? Thanks!