英特尔编译器和使用 constexpr 时的"cannot have an in-class initializer"
Intel compiler and "cannot have an in-class initializer" when using 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_[9] = {
<<p> 测试代码/strong> 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
为什么我收到错误"不能有一个类内初始化器"当使用constexpr
?
这是英特尔编译器的错误,已提交给英特尔,将在未来的版本中修复。
参见intel论坛上的多个constexpr bug、c++编译器15中的sfinae bug和c++编译器15中的方法constexpr bug。
看来你的编译器过时了。-std=c++0x
标志表明它早在c++ 11标准实现之前就实现了。
尝试使用-std=c++11
开关,如果你的编译器支持它。
否则,请升级编译器或不要使用这些花哨的新功能。
相关文章:
- 为什么static_assert错误:即使我传递常量"expression must have a constant value"?
- 赛通"Cannot take address of memoryview slice"
- C++:如何将 unix 时间的字符串转换为 *tm?(使用时间错误:"cannot convert 'String' to 'tm*' ")
- /usr/bin/ld: cannot find -lc++
- 错误:"Left of getValue must have class/struct/union"
- Cannot find -lglad
- "Cannot find -l<directory>"错误 - CMake
- Windows cannot find MinGW
- Visual Studio "fatal error LNK1104: cannot open file"未使用或包含的库
- "Cannot convert Python object argument to type '<typename>'" - 使用 Cython 包装 C++ 类时出错
- unordered_set .find 方法无法编译的 C++ "expression must have class type"错误
- SFINAE:"enable_if cannot be used to disable this declaration"
- cannot find -lMagick++-6.Q16
- C++ "'Shape': cannot instantiate abstract class"找不到问题的根源
- 我一直收到错误"cannot convert 'float*' to 'float' in return"
- 封送指向结构异常"cannot Read or Write protected memory"的指针数组的指针数组
- VS 2017 C++ - "cannot open source file 'sqlite3.h' "
- 警告的原因是什么:"when type is in parentheses, array cannot have dynamic size"?
- 为什么这段代码抱怨"a non-type template parameter cannot have type"?
- 英特尔编译器和使用 constexpr 时的"cannot have an in-class initializer"