在C ++ 11中,命名空间-static是否仍然被弃用? [英] Is namespace-`static` still deprecated in C++11?

查看:338
本文介绍了在C ++ 11中,命名空间-static是否仍然被弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

弃用静态关键字…没有更多?

在C ++ 2003中,命名空间 - static 已弃用:

In C++2003, namespace-static is deprecated:


[C ++ 03:7.3.1.1 / 2]:
在命名空间范围中声明对象时,不推荐使用 static 关键字(见附件D)。
未命名命名空间提供了一个更好的选择。

[C++03: 7.3.1.1/2]: The use of the static keyword is deprecated when declaring objects in a namespace scope (see annex D); the unnamed-namespace provides a superior alternative.

这样的子句存在于C ++ 2011(建议不推荐), 7.1.1 似乎禁止命名空间 - static (如果有,这表明该特征最终从语言中删除);但是, C.2 (列出了2003年和2011年之间的显着差异)中没有列出。

I can't find where any such clause exists in C++2011 (suggesting undeprecation), and 7.1.1 doesn't seem to prohibit namespace-static (and if it had, this would suggest that the feature had been finally removed from the language); however, neither case is listed in C.2 (which itemises significant differences between 2003 and 2011).

推荐答案

取消重新命名空间 - static 提议的并接受n3296

Undeprecating namespace-static was proposed and accepted for n3296:


ID: FI 6

参考: D.2 [depr.static]¶第1段

注释:不应弃用在命名空间范围中使用静态。匿名命名空间不能充分代替功能。

建议的分辨率:完全击败[depr.static]。

业主: CWG

问题: 1012

处置: ACCEPTED

ID: FI 6
Ref: D.2 [depr.static] ¶ Paragraph 1
Comment: The use of static in namespace scope should not be deprecated. Anonymous namespaces are not a sufficient replacement for the functionality.
Proposed Resolution: Strike [depr.static] completely.
Owner: CWG
Issue: 1012
Disposition: ACCEPTED

其实,C条款(关于兼容性)不列出对D条款的任何修改,所以很难说一目了然。 但是,不,命名空间 - static 不再在C ++ 11中弃用。

In fact, clause C (on compatibility) does not list any changes made to clause D (on deprecation), so it's hard to tell "at a glance". But, no, namespace-static is no longer deprecated in C++11.

这篇关于在C ++ 11中,命名空间-static是否仍然被弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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