如果命名空间只能有一个全局范围,那怎么会有嵌套的命名空间呢?

If Namespaces can only have a Global Scope how can there be Nested Namespaces?

我阅读了这 2 段代码及其描述,认为它们相互冲突。

  1. Namespace definition can appear only in a global scope.
void f()
{
    namespace space1{

    }
}
// So this is not allowed as space1 is local to f()
  1. Namespaces can be nested
namespace namespace1{
    int i;
    namespace namespace2{
       int j;
    }
}

在这种情况下,命名空间 2 不会在命名空间 1 的本地,从而导致错误吗?

因为你的报价是错误的。更正确的描述是:

Namespace definitions are only allowed at namespace scope, including the global scope.