是否有特定的原因在C ++中不允许嵌套名称空间声明? [英] Is there a specific reason nested namespace declarations are not allowed in C++?

查看:107
本文介绍了是否有特定的原因在C ++中不允许嵌套名称空间声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该标准不允许使用以下代码:

The standard does not allow code like this:

namespace Hello::World {

//Things that are in namespace Hello::World

}

而是要求

namespace Hello { namespace World {

//Things that are in namespace Hello::World

}}

基本原理是什么?当时只是没有想到这一点,还是有特定原因不包括在内?

What is the rationale? Was this simply not thought of at the time, or is there a specific reason it is not included?

第一种语法似乎更直接地表示应该在哪个名称空间中使用,因为该声明模仿了后续代码中名称空间的实际使用.如果您不幸使用了哑"括号计数缩进工具,那么缩进次数也会减少.

It seems that the first syntax more directly expresses in which namespace one is supposed to be, as the declaration mimics the actual use of the namespace in later code. It also results in less indentation if you are unfortunate enough to be using a "dumb" bracket counting indentation tool.

推荐答案

原因很可能是因为这就是语言的发展方式".

The reason is most likely "because that's how the language evolved."

至少有一项提案( 嵌套名称空间定义提案"(2003年)),以允许嵌套名称空间定义,但并未选择将其包含在C ++ 0x中.

There has been at least one proposal ("Nested Namespace Definition Proposal" in 2003) to allow nested namespace definitions, but it was not selected for inclusion in C++0x.

这篇关于是否有特定的原因在C ++中不允许嵌套名称空间声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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