且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

匿名名称空间中的对象是否隐式静态?

更新时间:2023-11-19 23:35:04

C ++ 11,3.5 / 4:

C++11, 3.5/4:


未命名空间或在未命名空间中直接或间接声明的
具有内部联系。所有其他命名空间
具有外部链接。如果上面的内部链接给出的名称空间范围不是
,那么它的名称与封闭的
名称空间具有相同的链接,如果它是—变量的名称...

An unnamed namespace or a namespace declared directly or indirectly within an unnamed namespace has internal linkage. All other namespaces have external linkage. A name having namespace scope that has not been given internal linkage above has the same linkage as the enclosing namespace if it is the name of — a variable ...

因此,在C ++ 11中,您的两个 foo 对象都具有内部链接。在C ++ 03中,第一个具有外部链接。

So in C++11 both of your foo objects have internal linkage. In C++03, the first one has external linkage.

与链接无关,它具有静态存储持续时间。

Regardless of linkage, it has static storage duration.

我认为标准中没有将对象当作标记为静态对象这样的东西,所以我无法回答。如果您在标准中找到一些有关对象是否被标记为静态的文字,并且没有专门提及链接或存储持续时间,请引用该文字,我可以给您一个意见:-)

I don't think there's any such thing in the standard as "take the object as if it was marked static", so I can't answer to that. If you find some text in the standard that refers to whether the object is "marked static" and doesn't refer specifically to either linkage or storage duration, then cite it and I can give you an opinion :-)