Please help me clear my doubts, regarding C++ namespaces.
For what I know, Namespace defines a scope. Members defined inside namespace have that namespace scope.
And An object cannot be accessed outside it's scope.
1. If that is true how are we able to access a namespace member outside the namespace ?
2. Do member of namespace have global scope ?
3. If namespace members do not have global scope they should not have been accessible outside the namespace scope, Am I correct ?
Please help me clear my doubts.
For what I know, Namespace defines a scope. Members defined inside namespace have that namespace scope.
And An object cannot be accessed outside it's scope.
1. If that is true how are we able to access a namespace member outside the namespace ?
2. Do member of namespace have global scope ?
3. If namespace members do not have global scope they should not have been accessible outside the namespace scope, Am I correct ?
Code:
namespace n {
int i = 10; // scope limited to n namespace
}
int main(){
std::cout << n::i; // ???? how we are able to access i here ???
return 0;
}
Comment