constant variables not working in header

后端 未结 10 2007
悲&欢浪女
悲&欢浪女 2020-11-30 20:10

if I define my constant varibles in my header like this...

extern const double PI = 3.1415926535;
extern const double PI_under_180 = 180.0f / PI;
extern cons         


        
10条回答
  •  猫巷女王i
    2020-11-30 20:46

    A lot of incorrect responses below. The ones that are correct are the ones telling you to remove the extern as sellibitze has also said in his comment are correct.

    Because these are declared const, there is no problem having the definition in the header. C++ will inline a const for a built in type unless you attempt to take its address (a pointer to a const) in which case it will instantiate it with static linkage, you may then also get multiple instantiations in separate modules, but unless you expect all pointers to the same const to have the same address, this is not a problem.

提交回复
热议问题