I noticed C++ will not compile the following:
class No_Good {
static double const d = 1.0;
};
However it will happily allow a variation where the double is changed to an int, unsigned, or any integral type:
class Happy_Times {
static unsigned const u = 1;
};
My solution was to alter it to read:
class Now_Good {
static double d() { return 1.0; }
};
and figure that the compiler will be smart enough to inline where necessary... but it left me curious.
Why would the C++ designer(s) allow me to static const an int or unsigned, but not a double?
Edit: I am using visual studio 7.1 (.net 2003) on Windows XP.
Edit2:
Question has been answered, but for completion, the error I was seeing:
error C2864: 'd' : only const static integral data members can be initialized inside a class or struct