3

What are the reasons due to which the in-class initialization of static const members is restricted to integral data types in C++ ?

Piotr Skotnicki
  • 46,953
  • 7
  • 118
  • 160
Ujjwal Aryan
  • 3,827
  • 3
  • 20
  • 31
  • 3
    I always thought the rationale was the same as for why only integral types are allowed as template parameters, though I don't actually know what that rationale is. – Kerrek SB Aug 11 '15 at 20:29
  • 1
    @CaptainObvlious: It's kind of still the case, though. Sure, you have an *alterative* mechanism with `constexpr`, but the restriction on `const` members is unchanged, isn't it? – Kerrek SB Aug 11 '15 at 20:32
  • 1
    For C++11 the rationale is different see [Constant expression initializer for static class member of type double](http://stackoverflow.com/q/30742288/1708801) – Shafik Yaghmour Aug 11 '15 at 20:33
  • @KerrekSB Yup, correct you are. I was thinking of non-static members – Captain Obvlious Aug 11 '15 at 20:34

0 Answers0