Skip to content

Instantly share code, notes, and snippets.

@tmplt
Created July 6, 2014 12:55
Show Gist options
  • Save tmplt/18c7d2ac6154008c0524 to your computer and use it in GitHub Desktop.
Save tmplt/18c7d2ac6154008c0524 to your computer and use it in GitHub Desktop.
explicitly requests a global name over a local one
using namespace std;
int reused = 42; // global scope
int main()
{
int unique = 0; // block/local scope
// output #1: uses global reused; prints "42 0"
cout << reused << " " << unique << endl;
int reused = 0; // new, local name, hides (currently overrides?) global name
// output #2: uses local reused; prints "0 0"
cout << reused << " " << unique << endl;
// output #3: explocitly requests global name; prints "42 0"
cout << ::reused << " " << unique << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment