constant variables not working in header

后端 未结 10 2006
悲&欢浪女
悲&欢浪女 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条回答
  •  时光说笑
    2020-11-30 20:23

    You need to declare the contants in the header and then define them in one of your code files. If you do not declare them anywhere, then there is a linker error when it tries to tie the declaration to the actual definition. You can also get away with using #ifdef statements to have one definition within the header.

    Make sure they are declared in a header that is included by everyone that needs them and make sure they are defined exactly once.

    Jacob

提交回复
热议问题