anonymous namespace

后端 未结 5 472
南旧
南旧 2020-12-25 14:03

What is the different between these two?

cpp-file:

namespace
{
    int var;
}

or

int var;

if both

5条回答
  •  隐瞒了意图╮
    2020-12-25 14:33

    In addition to the reason given by Nikolai and others, if you don't use an anonymous namespace, you can get naming conflicts with other global data. If you do use an anonymous namespace, you will instead shadow the global data.

    From cprogramming.com: "Within the namespace you are assured that no global names will conflict because each namespace's function names take precedence over outside function names."

提交回复
热议问题