The only difference between declaring an external variable in a namespace scope is:
extern int x; void foo() { cout << x; }
and declare it in the function area:
void foo() { extern int x; cout << x; }
lies in the fact that in the latter case, x is visible only inside the function.
Everything you do extern declaration area even more.
Here's a similar example using namespaces:
In the namespace area:
#include <string> using std::string; void foo() { string str1; } string str2; // OK
In the area of ββfunctions:
#include <string> void foo() { using std::string; string str1; } string str2; // Error - `using` not performed at this scope
source share