Why aren't static const floats allowed?

后端 未结 6 2201
无人及你
无人及你 2020-11-29 02:25

I have a class which is essentially just holds a bunch of constant definitions used through my application. For some reason though, longs compile but floa

6条回答
  •  爱一瞬间的悲伤
    2020-11-29 03:07

    You should initialize them in the body of one of your cpp files:

    class MY_CONSTS
    {
    public :
        static const long   LONG_CONST = 1;      // Compiles 
        static const float FLOAT_CONST;
    };
    
    const float MY_CONSTS::FLOAT_CONST = 0.001f;
    

提交回复
热议问题