static vs non-static variables in namespace

前端 未结 4 1161
余生分开走
余生分开走 2020-12-04 23:54

I have a namespace foo which contains an integer bar, declared so...

foo.h:

namespace foo {
    int bar;
}
<
4条回答
  •  余生分开走
    2020-12-05 00:23

    Also note that const int at namespace (global) scope in C++ has static implicitly added by default: Define constant variables in C++ header

    To better understand what is going on, do a readelf on the intermediate ELF object files of the compilation, and you will see clearly is symbols are defined twice or not. Here is a detailed example: What does "static" mean in C?

提交回复
热议问题