static keyword useless in namespace scope?

后端 未结 6 1882
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 12:30
namespace N
{
   static int x = 5;
}

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

6条回答
  •  自闭症患者
    2021-01-01 12:46

    C++ Standard §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.

    Unless the unnamed namespace provides a superior alternative in the future Standard it will be undeprecated to achieve C compatibility.

提交回复
热议问题