* Ron Natalie:
> red floyd wrote:
>> Miguel Guedes wrote:
>>> Hello,
>>>
>>> Why can't non-integral static const data members be initialized
>>> within a class?
>>>
>>> I know how to initialize the members but I don't understand the
>>> underlying
>>> reason to this rule. Would someone explain this to me?
>>>
>>> Example:
>>>
>>> class foo
>>> {
>>> public:
>>> static const float f = 0.02f; // Error!
>>> static const int i = 1; // Valid.
>>> };
>>>
>>>
>>
>> Because the Standard says so. I don't know if this has been changed in
>> the draft 0x standard.
>>
> The issue is that the compiler is expectedto know how to execute
> const integral expressions at compile time, so the const inline int
> makes sense. The compiler is not required to be able to do floating
> point at compile time (it may assume that it's too hard to crosscompile).
Sorry, while that is relevant it's not a valid reason to forbid the
syntax. It's only a valid reason to forbid the use of e.g. a named
double constant at compile time (e.g. casted to int). As I've shown
else-thread, you can easily achieve the effect of having a constant
float foo::f, so any standard-conforming compiler must support the
effective functionality, just not the sensible syntax: it's explicitly
not allowed to support the sensible /syntax/, so the question is why on
Earth not, and the answer, probably, politics and arbitrary history.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?