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++?
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
