Uses for anonymous namespaces in header files(用于头文件中的匿名命名空间)
问题描述
今天有人在 SO 上断言,你永远不应该在头文件中使用匿名命名空间.通常这是正确的,但我似乎记得曾经有人告诉我其中一个标准库在头文件中使用匿名命名空间来执行某种初始化.
Someone asserted on SO today that you should never use anonymous namespaces in header files. Normally this is correct, but I seem to remember once someone told me that one of the standard libraries uses anonymous namespaces in header files to perform some sort of initialization.
我没记错吗?有人可以填写详细信息吗?
Am I remembering correctly? Can someone fill in the details?
推荐答案
header 中的无名命名空间唯一有用的情况是,当您只想将代码作为头文件分发时.例如,Boost 的一个大型独立子集纯粹是标头.
The only situation in which a nameless namespace in header can be useful is when you want to distribute code as header files only. For example, a large standalone subset of Boost is purely headers.
另一个答案中提到的元组标记 ignore
是一个例子,_1
、_2
等绑定占位符是其他的.
The token ignore
for tuples, mentioned in another answer is one example, the _1
, _2
etc. bind placeholders are others.
这篇关于用于头文件中的匿名命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于头文件中的匿名命名空间


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01