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

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

问题描述

std 命名空间在 C++ 中是特殊的,所以 ...

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

这是合法的 C++ 吗?

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.

推荐答案

reserved names 标准 17.4.3.1(及其子段落)中我找不到任何禁止使用 std 作为嵌套命名空间名称.它不是宏,不在全局命名空间中,而且似乎不符合任何禁止它的外部链接标准".

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).

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

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