C ++中的一个定义规则究竟是什么? [英] What exactly is One Definition Rule in C++?

查看:224
本文介绍了C ++中的一个定义规则究竟是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中的一个定义规则究竟是什么?唯一值得信赖的发现是我可以在 C ++编程语言,第三。 ed。,P. 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 ++中的一个定义规则究竟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆