Is it legal C++ to declare a nested namespace `std`?(声明嵌套命名空间`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++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:声明嵌套命名空间`std`是否合法C++?
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
