static keyword useless in namespace scope?

后端 未结 6 1851
隐瞒了意图╮
隐瞒了意图╮ 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 13:01

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

    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 keyword imparts internal linkage to variables/objects in C as well as in C++ in namespace scope as others have mentioned in their posts.

    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.

提交回复
热议问题