C++11 英特尔编译器与";不能有类内初始值设定项";使用constexpr时
以下测试程序使用g++编译并运行良好。对于Intel icpc(14.0.2),如果我使用显式类型(如double)而不是模板,它将编译并运行。带有icpc的模板版本产生错误:C++11 英特尔编译器与";不能有类内初始值设定项";使用constexpr时,c++11,constexpr,C++11,Constexpr,以下测试程序使用g++编译并运行良好。对于Intel icpc(14.0.2),如果我使用显式类型(如double)而不是模板,它将编译并运行。带有icpc的模板版本产生错误: icpc -g -O2 -I. -std=c++0x -c main.cc -o main.o main.cc(10): error: a member of type "const T [9]" cannot have an in-class initializer static constexpr T dx
icpc -g -O2 -I. -std=c++0x -c main.cc -o main.o
main.cc(10): error: a member of type "const T [9]" cannot have an in-class initializer
static constexpr T dx_[9] = {
测试代码
template<typename T>
class myclass {
public:
static constexpr T dx_[9] = {
1.5, 2.0, -0.5,
-0.5, 0.0, 0.5,
0.5, -2.0, -1.5
};
};
template<typename T> constexpr T myclass<T>::dx_[9];
int main(int argc, char *argv[]) {
return 0;
} // main
模板
类myclass{
公众:
静态constexpr T dx_9]={
1.5, 2.0, -0.5,
-0.5, 0.0, 0.5,
0.5, -2.0, -1.5
};
};
模板constexpr T myclass::dx_9];
int main(int argc,char*argv[]){
返回0;
}//主要
为什么我在使用
constexpr
时收到错误“不能有类内初始值设定项”?您的编译器似乎过时了。-std=c++0x
标志表明它早在c++11标准实现之前就已经实现了
如果编译器支持,请尝试使用-std=c++11
开关
否则,请升级您的编译器或不要使用这些新奇的新功能。这是英特尔编译器的一个错误,它已提交给英特尔,并将在未来版本中修复
另请参见和英特尔论坛。这里技术上没有问题。不要使用这些花哨的新功能。这些功能不是新功能,但(在OP时)已超过2年。@Walter:也就是说,
constepr
在最新的VisualStudio 2015 CTP上仍然不完全受支持。尽管我很难说,如果你的兼容性很强,你就不应该使用这些特性。我认为这里的缺陷是英特尔而不是C++用户。英特尔辜负了他们的客户,他们应该停止为如此糟糕的服务付费@在理想的世界里,我绝对同意。但在Windows上,我们只使用现有的工具。