What exactly is One Definition Rule in C++?(C++中的一个定义规则到底是什么?)
问题描述
C++ 中的一个定义规则到底说的是什么?我能找到的唯一值得信赖的出现在 The C++ Programming Language, 3rd.编,第 9.2.3 页.除此以外,是否还有其他正式的规则定义?
What exactly does One Definition Rule in C++ say? The only trustworthy occurence I can find is in The C++ Programming Language, 3rd. ed., P. 9.2.3. Is there any official definition of the rule except that?
推荐答案
真理在标准中(3.2一定义规则):
The truth is in the standard (3.2 One definition rule) :
任何翻译单元不得包含更多不是任何变量的一个定义,函数、类类型、枚举类型或模板.
No translation unit shall contain more than one definition of any variable, function, class type, enumeration type or template.
[...]
每个程序都应准确包含每个非内联的一个定义中使用的函数或对象 那个程序;无需诊断.定义可以显式出现在程序中,它可以在标准或用户定义的库,或(在适当的时候)它是隐含的定义(见 12.1、12.4 和 12.8).一个内联函数应定义在它所在的每个翻译单元用过.
Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required. The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriate) it is implicitly defined (see 12.1, 12.4 and 12.8). An inline function shall be defined in every translation unit in which it is used.
这篇关于C++中的一个定义规则到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++中的一个定义规则到底是什么?


基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01