anonymous namespace

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

    In the second case other .cpp files can access the variable as:

    extern int var;
    var = 42;
    

    and the linker will find it. In the first case the variable name is mangled beyond any reason :) so the above is not possible.

提交回复
热议问题