Well i was just creating my particle engine in OpenGL and i thought of using classes instead of Structs, and i eventually ran into this static const float..
I never knew they could not be initialized in Class,
For ex,
class cType
{
private:
static const int Num = 10; // Ok.
static const float color = ... // Error
};
If you don't want to separate the definition and the declaration, you can go with the function approach.
[source]
class cType
{
private:
static const int Num = 10; // Ok.
static float color() {return ... ;}
};
[/source]
As Antheus said, it's because the standard says so. It simply allows for integer types only to be initialized like that, so floating point types have to be defined the normal way with separate definition in a single translation unit. At least pre-C++11...
No, it's because float isn't a integral or enumeration type. Under C++03 those were the only kinds of static data members you could initialize in the body of a class or struct.