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