Okay to declare static global variable in .h file?

后端 未结 6 1997
野趣味
野趣味 2020-12-13 07:36

static keyword keeps the scope of a global variable limited to that translation unit. If I use static int x in a .h file and include that .h file every

6条回答
  •  抹茶落季
    2020-12-13 08:27

    you will end up will private copies of that variable per translation, which will result in bloat if you put it there. it would also make no sense to have to random copies all over the place. no it's not ok.

    you can declare a const int in a namespace block; that's ok.

提交回复
热议问题