且构网

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

弃用 static 关键字...不再使用?

更新时间:2021-08-28 04:07:46

C++ 标准核心语言缺陷报告和已接受的问题,修订版 941012.不赞成静态他们注意到:

In C++ Standard Core Language Defect Reports and Accepted Issues, Revision 94 under 1012. Undeprecating static they note:

尽管 7.3.1.1 [namespace.unnamed] 声明不推荐使用 static 关键字在命名空间范围内声明变量,因为未命名命名空间提供了更好的选择,但该功能不太可能在任何时候被删除可预见的未来.

Although 7.3.1.1 [namespace.unnamed] states that the use of the static keyword for declaring variables in namespace scope is deprecated because the unnamed namespace provides a superior alternative, it is unlikely that the feature will be removed at any point in the foreseeable future.

基本上这是说弃用 static 并没有真正的意义.它永远不会从 C++ 中删除.它仍然很有用,因为如果您只想声明具有内部链接的函数或对象,则不需要带有未命名 namespace 的样板代码.

Basically this is saying that the deprecation of static doesn't really make sense. It won't ever be removed from C++. It's still useful because you don't need the boilerplate code you would need with unnamed namespace's if you just want to declare a function or object with internal linkage.