Initialization of "static constexpr double" with MSVC 2013

The title says this, and both of the usual methods do not work. What am I missing?

1.

class Cl { static constexpr double PI; }; constexpr double Cl::PI = 3.14; 

(26): error C2737: 'private: static double const Cl :: PI: the constexpr object must be initialized

2.

 class Cl { static constexpr double PI = 3.14; }; 

(26): error C2864: 'Cl :: PI': a static data member with an initializer in the class must have a non-volatile const integral type
type - 'const double'

In both attempts, the error is on the same line inside the class. I am using CTP VisualStudio / MSVC compiler Nov 2013.

Note that creating a const variable is not a solution, because I want to use this constant in both constexpr functions and normal functions.

+6
source share
2 answers

In the tables and explanations from Stephan TL in this blog , constexpr is really only partially implemented in VS 10 2013 CTP.

CTP supports C ++ 11 constexpr, with the exception of member functions. (Another limitation is that arrays are not supported.) Also, this does not support the extended constexpr C ++ 14 rules.

(I would like to put it in the comments, but there are not enough points yet)

Edit: Just add a blog to Herb, there is almost the same question about static members, but the answer is the same as Stephan.

I think we can simply say that Nov 2013 CTP does not implement the required OP function (send a bug report?) And wait for July 2014 CTP or VS Next (unfortunately).

+4
source

You cannot "initialize" constexpr. As the keyword implies, this is a constant expression, not a variable.

It seems you just want to use const here.

The compiler in the second example simply indicates that you cannot create all types of const-expr.

Update . This is a limitation of MSVC.

glad to fulfill the obligation.

In fact, the C ++ 11 support page : no constexpr support in MSVC2010-2013

+1
source

All Articles