Created
July 6, 2014 12:55
-
-
Save tmplt/18c7d2ac6154008c0524 to your computer and use it in GitHub Desktop.
explicitly requests a global name over a local one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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