Why aren't static const floats allowed?

Posted by Jon Cage on Stack Overflow See other posts from Stack Overflow or by Jon Cage
Published on 2010-03-16T11:49:51Z Indexed on 2010/03/16 11:56 UTC
Read the original article Hit count: 334

Filed under:
|

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 floats do not:

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

Gives the following error:

1>c:\projects\myproject\Constant_definitions.h(71) : error C2864: 'MY_CONSTS::FLOAT_CONST' : only static const integral data members can be initialized within a class

Am I missing something?

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++