静态关键字在命名空间范围内无用? [英] static keyword useless in namespace scope?

查看:156
本文介绍了静态关键字在命名空间范围内无用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

namespace N
{
   static int x = 5;
}

可以是声明具有静态变量的重要性/用例命名空间范围?

What could be the importance/use-cases of declaring having a static variable at namespace scope?

推荐答案

附件D(兼容性功能)[C ++ 03]

Annex D (Compatibility features) [C++03]


D2:当在命名空间范围中声明对象时,static关键字的使用已过时。

D2: The use of the static keyword is deprecated when declaring objects in namespace scope.

使用未命名的命名空间,而不是帖子中所述。

Use unnamed namespaces instead as mentioned in this post.

static关键字赋予C中的变量/对象以及C ++在命名空间范围内的内部链接,正如其他人在其帖子中提到的那样。

static keyword imparts internal linkage to variables/objects in C as well as in C++ in namespace scope as others have mentioned in their posts.

PS:
此功能已根据最新草稿(n3290)未淘汰。在n3225 §7.3.1.1/ 2 已存在但已删除。

P.S: Thie feature has been undeprecated as per the latest draft (n3290). In n3225 §7.3.1.1/2 is present but striked out.

这篇关于静态关键字在命名空间范围内无用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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