Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ GNU版本问题与GNU++;0x标准_C++_C++11_Standards_Gnu - Fatal编程技术网

C++ GNU版本问题与GNU++;0x标准

C++ GNU版本问题与GNU++;0x标准,c++,c++11,standards,gnu,C++,C++11,Standards,Gnu,我需要用两个编译器版本编译代码: g++(Ubuntu/Linaro 4.7.3-1ubuntu1)4.7.3 g++(Ubuntu/Linaro 4.6.3-1ubuntu5)4.6.3 我在头文件中有一段代码,如下所示: template <RealType> class Constant { ... /*constexpr*/ static const RealType Pi = 3.14159265358979323846264338327950288419716

我需要用两个编译器版本编译代码:

g++(Ubuntu/Linaro 4.7.3-1ubuntu1)4.7.3

g++(Ubuntu/Linaro 4.6.3-1ubuntu5)4.6.3

我在头文件中有一段代码,如下所示:

template <RealType> class Constant {
   ...
   /*constexpr*/ static const RealType Pi = 3.1415926535897932384626433832795028841971693993751;
   ...
};
但是,如果我不使用
constexpr
4.6.3版,则会出现以下问题:

error: ‘constexpr’ needed for in-class initialisation of static data member ‘const double Constant<double>::Pi’
错误:静态数据成员“const double Constant::Pi”的类内初始化需要“constexpr”
有解决办法吗


顺便说一句,如果我省略
-std=gnu++0x
(当然还有
constexpr

const对于变量来说是多余的,那么代码构建得很好。只是
constexpr
,就像这样:

static constexpr RealType Pi = 3.14;


在C++14中,您甚至可以说

template <typename T> constexpr Pi = T(3.14);
模板constepr Pi=T(3.14);

当你说“代码构建良好”时,你确定要启用所有警告和
-pedantic
吗?你知道GCC 4.6.3支持的C++11比4.7.3少,是吗?@Nicolas是的,我知道。但也有其他因素。这是一个更大的项目。我想,我可以自己解决这个问题。谢谢
template <typename T> constexpr Pi = T(3.14);