I read these 2 pieces of codes and their descriptions and thought that they were clashing with each other.
- Namespace definition can appear only in a global scope.
void f()
{
namespace space1{
}
}
// So this is not allowed as space1 is local to f()
- Namespaces can be nested
namespace namespace1{
int i;
namespace namespace2{
int j;
}
}
In this case won't namespace2 be local to namespace1 thus resulting in an error?
Because your quote is wrong. A more correct description would be:
Namespace definitions are only allowed at namespace scope, including the global scope.