gpt4 book ai didi

c++ - 我相信短语 "not previously declared to have external linkage"在 N4140 的§3.5/3 项目符号点 (3.2) 中是多余的

转载 作者:太空宇宙 更新时间:2023-11-04 16:07:16 24 4
gpt4 key购买 nike

§3.5[basic.link]/3(我的重点):

A name having namespace scope (3.3.6) has internal linkage if it is the name of

(3.1) — a variable, function or function template that is explicitly declared static; or,

(3.2) — a non-volatile variable that is explicitly declared const or constexpr and neither explicitly declared extern nor previously declared to have external linkage; or

(3.3) — a data member of an anonymous union.

我认为 (3.2) 中粗体字的短语是多余的,除非有人可以给出一个显式声明为 const 但未声明为 extern 的变量的示例>,并且之前被声明为具有外部链接,因此结果变量具有外部链接

最佳答案

这很简单:

extern const int i; // typically in header file
const int i = 0; // typically in source file

你问题中的句子确保这里没有冲突。第二个声明没有指定不同的不兼容链接,它只是继承了前一个声明的链接,并且是您问题中的单词实现了这一点。

关于c++ - 我相信短语 "not previously declared to have external linkage"在 N4140 的§3.5/3 项目符号点 (3.2) 中是多余的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33376124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com