12
#include <iostream> #include <string> using namespace std; string a; namespace myNamespace { string a; void output() { cout << a << endl; } } int main() { a = "Namespaces, meh."; myNamespace::a = "Namespaces are great!"; myNamespace::output(); } 

The result is "Namespaces are great!". So is there any way to access the global string a inside of the namespace myNamespace instead of just the local one?

1 Answer 1

17

Like this:

void output() { cout << ::a << endl; //using :: = the global namespace } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.