Hello,
I am reading a book and am curious about a statement it makes:
"Anything declared in a block that contains a nested block is nonlocal to the inner block. (Global identifiers are nonlocal with respect to all blocks in the program.)"
I always thought of "a" declared within myFunction as local to the function. But the book suggests that within the while statement it is nonlocal. Is this correct? How does C++ see a difference between two nonlocal variables? What exactly does C++ do when "name hiding"?Code:int a = 1; //global, nonlocal void myFunction() { int a = 2; //local, hides global a while (a < 3) { a++; //a is nonlocal here? } }
EDIT: Just keeps reading backwards until it finds one.



2Likes
LinkBack URL
About LinkBacks



