The name of the variable could be something intuitive, I used 'i' for this example.
It does not affect the example. The sketch below works fine.
//A global
int i = 666;
void setup()
{
int i = 2 * 2;
Serial.begin( 9600 );
Serial.print( "2 squared = " );
Serial.print( i );
return;
}
void loop(){return;}
In my previous example,
The global is a non-dependant name, it is satisfying a rule where non-dependant names in dependant types take the last definition seen. The compiler doesn't consider the base class during name lookup, even though its 'i' is the closer scope. This is quite different to the snippet above where the closer scope is setup::i which is also used.
So rather than receiving an error about 'i' being undefined in the class ( 'this->' is required to make the name dependant ), the previous definition of 'i' is silently used.
As a minimum, place the global in a namespace so it has to be explicitly used.