使用MSVC 2013初始化“静态constexpr double” [英] Initializing a `static constexpr double` with MSVC 2013

查看:119
本文介绍了使用MSVC 2013初始化“静态constexpr double”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切,并且两种常规方法均无效。我想念什么?

Title says it all and both of the usual ways do not work. What am I missing?

1。

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




(26):错误C2737:'private:静态double const
Cl :: PI': constexpr对象必须初始化

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

2。

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




(26):错误C2864:'Cl :: PI':具有类内初始化程序的静态
数据成员必须具有非易失性const
整数类型

类型为'const double'

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

在两次尝试中,错误均在类内的同一行上。我正在使用VisualStudio / MSVC 2013年11月CTP编译器。

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

请注意,使变量 const 不是解决方案因为我想在constexpr函数和普通函数中都使用此常量。

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

推荐答案

由Stephan TL提供的表格和说明博客 constexpr 实际上仅在VS 2013年11月CTP中部分实现。

By the tables and explanation from Stephan T. L. in this blog, the constexpr is indeed only partially implemented in VS Nov 2013 CTP.


CTP支持C ++ 11 constexpr,成员函数除外。
(另一个限制是不支持数组。)而且,它也不
支持C ++ 14的扩展constexpr规则。

The CTP supports C++11 constexpr, except for member functions. (Another limitation is that arrays aren't supported.) Also, it doesn't support C++14's extended constexpr rules.

(希望将其添加到注释中,但尚无足够要点)

(wish to put it in comments, but no sufficient points yet)

编辑:只需在Herb的博客,关于静态的问题也差不多

Just to add, in Herb's blog, there is near same question about static members, but the reply is the same as Stephan.

我认为可以简单地说2013年11月CTP未实现必需的OP功能(发送错误报告? )并等待2014年7月的CTP或VS Next(可悲)。

I think it is safe to simple say that Nov 2013 CTP not implement the required OP feature (send a bug report?) and wait for a Jul 2014 CTP or VS Next (sadly).

这篇关于使用MSVC 2013初始化“静态constexpr double”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆