是否合法的C ++声明一个嵌套的命名空间`std`? [英] Is it legal C++ to declare a nested namespace `std`?

查看:122
本文介绍了是否合法的C ++声明一个嵌套的命名空间`std`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std 命名空间在C ++中是特殊的,因此...



这是合法的C ++吗? p>

  //在全局范围
命名空间mine {
命名空间std {
...
}
}



我会说它疯了, / p>

请注意标准中的引用(或非引用)。

解决方案

保留名称标准17.4.3.1(及其子段落)我找不到任何禁止使用 std 作为嵌套命名空间名称。它不是一个宏,它不在全局命名空间,它似乎不符合任何禁止它的外部链接标准。



是合法的(虽然你注意到非常不合适)。


The std namespace is special in C++, so ...

Is this legal C++?

// at global scope
namespace mine {
  namespace std {
    ...
  }
}

I'd call it insane, but is it allowed?

A reference (or non-reference) from the Standard would be appreciated.

解决方案

In the reserved names standard 17.4.3.1 (and its sub-paragraphs) I can't find anything that prohibits using std as a nested namespace name. It's not a macro, it's not in the global namespace, and it doesn't seem to meet any of the "external linkage criteria" that would prohibit it.

It appears to be legal (although as you note extremely inadvisable).

这篇关于是否合法的C ++声明一个嵌套的命名空间`std`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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