2
当编译此代码铛(3.0-6ubuntu3版):无法初始化constexpr
constexpr int foo(const int n) {
return n + 1;
}
int main(void) {
constexpr int x = 5 * 4 + 12 + 8;
constexpr int y = foo(x);
return 0;
}
使用这个命令:
clang -std=c++11 -c constexprExample.cpp
我获得以下错误:
error: constexpr variable 'y' must be initialized by a constant expression
代码或编译器有问题吗?
尝试将y定义为常量而不是常量表达式.... – asalic