3 Basic concepts [basic]3.2 One definition rule [basic.def.odr]
| 3 基本概念 【基本】3.2 唯一定义原则 【基本.定义.ODR】
|
No translation unit shall contain more than one definition of any variable, function, class type, enumeration type or template.
| 翻译单元中只能有任何变量,函数,类类型,枚举类型或模板的唯一定义。
|
An expression is potentially evaluated unless either it is the operand of the sizeof operator (5.3.3), or it is the operand of the typeid operator and does not designate an lvalue of polymorphic class type (5.2.8). An object or non-overloaded function is used if its name appears in a potentially-evaluated expression. A virtual member function is used if it is not pure. An overloaded function is used if it is selected by overload resolution where referred to from a potentially-evaluated expression. [Note: this covers calls to named functions (5.2.2), operator overloading (clause 13), user-defined conversions (12.3.2), allocation function for placement new (5.3.4), as well as non-default initialization (8.5). A copy constructor is used even if the call is actually elided by the implementation. ] An allocation or deallocation function for a class is used by a new expression appearing in a potentially-evaluated expression as specified in 5.3.4 and 12.5. A deallocation function for a class is used by a delete expression appearing in a potentially-evaluated expression as specified in 5.3.5 and 12.5. A copy-assignment function for a class is used by an implicitly-defined copy-assignment function for another class as specified in 12.8. A default constructor for a class is used by default initialization as specified in 8.5. A constructor for a class is used as specified in 8.5. A destructor for a class is used as specified in 12.4.
| 表达式被有效求值,除非它是 sizeof 运算符(5.3.3)的操作数,或者是 typeid 运算符的操作数,并且指定的不是多态类类型(5.2.8)的左值。在有效求值表达式中出现的对象或非重载函数的名字被应用。如果虚成员函数不是纯的,则其被应用。当重载函数在重载解析中被选择时,其将被应用在有效求值表达式中。【注:这包含对命名函数(5.2.2),运算符重载(章节 13),用户定义转换(12.3.2),放置 new 的存储分配函数(5.3.4),以及非默认初始化(8.5)的调用。对于复制构造函数,即使其调用实际上被实现省略,其仍然被应用。】在有效表达式中,new 表达式应用某类的存储分配或存储释放函数,见 5.3.4 和 12.5。在有效表达式中,delete 表达式应用某类的存储释放函数,见 5.3.5 和 12.5。某类的复制构造函数在另一个类隐式定义的复制构造函数中应用,见 12.8。某类的默认构造函数被默认初始化应用,见 8.5。某类的构造函数按 8.5 中所指定的被应用。某类的析构函数按 12.4 中所指定的被应用。
|
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 appropriated) 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.
| 每个程序必须仅包含该程序中应用的每个非内联函数或对象的唯一一个定义;无需诊断。该定义可以显式出现在程序中,可以在标准或用户定义的库中,或(在适当的时候)被隐含的定义(见 12.1,12.4 和 12.8)。内联函数应该在每个应用它的翻译单元中定义。
|
Exactly one definition of a class is required in a translation unit if the class is used in a way that requires the class type to be complete. [Example: the following complete translation unit is well-formed, even though it never defines X :
--end example] [Note: the rules for declarations and expressions describe in which contexts complete class types are required. A class type
| 如果某个类以需要其完整类型的方式被应用,则该类需要一个唯一定义。【例:如下的完整翻译单元是良好形式的,即使其没有定义 X :
--例完】【注:描述声明和定义在何中语境中需要完整类型的规则。某类型
|
There can be more than one definition of a class type (clause 9), enumeration type (7.2), inline function with external linkage (7.1.2), class template (clause 14), non-static function template (14.5.5), static data member of a class template (14.5.1.3), member function template (14.5.1.1), or template specialization for which some template parameters are not specified (14.7, 14.5.4) in a program provided that each definition appears in a different translation unit, and provided the definitions satisfy the following requirements. Given such an entity named D defined in more than one translation unit, then
| 类类型(章节 9),枚举类型(7.2),具有外部连接性的内联函数(7.1.2),类模板(章节 14),非静态函数模板(14.5.5),模板类静态数据成员(14.5.1.3),成员函数模板(14.5.1.1),或者未指明某些模板参数的模板特化(14.7,14.5.4),可以有多于一个定义,每个定义都出现在程序的不同翻译单元中,并且需要满足如下要求。给定实体命名为 D 在多于一个翻译单元中定义,则
|
25) 8.3.6 describes how default argument names are looked up.
| 25) 8.3.6 节描述怎样进行默认参数查找
|
PREV [basic.def] | NEXT [basic.scope] | 上一页 【基本.定义】 | 下一页 【基本.作用域】 |
3.2 - [basic.def.odr] - 【基本.定义.ODR】
最新推荐文章于 2020-04-21 09:24:45 发布
请不要转载本文;请不要以任何形式重新出版,发布本文;请在下载本文 24 小时内将其删除;禁止将本文用于商业目的。