为什么禁止打开多个命名空间? [英] Why is it forbidden to open multiple namespaces at a stretch?

查看:117
本文介绍了为什么禁止打开多个命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用命名空间foo :: bar; (即,使用内部命名空间而不使用外部命名空间首先/所有),为什么标准禁止要执行以下操作?

It's possible to do using namespace foo::bar; (i.e., using the inner namespace without using the outer namespace first / at all), why does the standard forbid to do the following?

namespace foo::bar {
  // open nested namespace bar in foo and extend it...
}



我不是在寻找解决方法,只是一个可能的理性为什么不允许这样做。

I'm not looking for a workaround, just a possible rational on why this isn't allowed.

推荐答案

我不确定禁止是正确的词 - 也许它只是监督。

I'm not sure "forbidden" is the right word - maybe it was just an oversight. It's a fairly small nice-to-have which isn't really a big deal.

你也可以认为命名空间是一个非常小的好处,写 foo :: bar 时,尚未创建foo ,因此允许该语法看起来像 foo

You could also take the point of view that the namespace foo isn't created yet when you write foo::bar, so allowing that syntax makes it look like foo was already created when it was not.

您还可以进一步请求写入 class Foo :: MyClass {... 在命名空间 Foo 中定义 MyClass ,变量等,但这个功能真的有必要,并解决任何特定的紧迫问题吗?

You could also go further and request the ability to write class Foo::MyClass {... to define MyClass in namespace Foo, and the same for functions, variables, etc. But is this feature really necessary and solving any particular pressing problem?

这篇关于为什么禁止打开多个命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆