lundi 1 février 2016

g++ I can declare a static const char but not a static const double? (!)

Here are two line of code:

static const double RYDBERG_CONST_EV = 13.6056953;

static const char CHAR_H_EDGE = '-';

The second line compiles without errors, the first line does not compile. (Error: 'constexpr' needed for in-class initialization of static data member...)

The solution is apparently to add the keyword constexpr before the type. This is required because double is not an "integral type". But why does gcc behaviour differ between integer and floating point types?

Aucun commentaire:

Enregistrer un commentaire