gpt4 book ai didi

c++ - 成员变量有外部链接吗?

转载 作者:太空狗 更新时间:2023-10-29 23:12:27 25 4
gpt4 key购买 nike

我已阅读 this上面写着

names of classes, their member functions, static data members (const or not), nested classes and enumerations, and functions first introduced with friend declarations inside class bodies

默认有外部链接。但是在类体内声明的未指定为静态的变量呢?此外,它以

开头

Any of the following names declared at namespace scope have external linkage

,但是类作用域是否被视为命名空间作用域?我的意思是类范围和命名空间范围是不同的,那么为什么他们一开始就说以下内容适用于在命名空间范围内声明的上述内容?我的意思是,例如,成员函数是在类作用域中声明的,并且它们提到它们时就好像它是命名空间作用域一样?

最佳答案

下面的例子:

class C
{
public:
int n;
};

C e;
namespace { C i; }

e 有外部链接,i 有内部链接。现在谈论 n 的链接有多大意义?如果有的话,您可以考虑 n 继承包含对象的链接,因此 e.n 将具有外部链接,i.n 内部链接 - 以便更好地理解只是,我不认为这是正确的措辞......

关于c++ - 成员变量有外部链接吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103512/

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