Hiding Names with File Scope

You can hide names with file scope by explicitly declaring the same name in block scope. However, file-scope names can be accessed using the scope-resolution operator (::). For example:

#include <iostream.h>

int i = 7;      // i has file scope--declared
                // outside all blocks

void main( int argc, char *argv[] )
{
   int i = 5;  // i has block scope--hides
                // the i with file scope

   cout << "Block-scoped i has the value: " << i << "\n";
   cout << "File-scoped i has the value: " << ::i << "\n";
}

The result of the preceding code is:

Block-scoped i has the value: 5
File-scoped i has the value: 7