anonymous namespace

后端 未结 5 506
南旧
南旧 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:37

    The second version is defined in the global namespace -- other .cpp files can get to it by declaring

    extern int var;

    and even if they don't do that, if someone else uses the same name in the global name space, you'll get a link error (multiply defined symbol).

提交回复
热议问题