“function”:调用不会生成常数表达式
声明为 constexpr 的函数只能调用声明为 constexpr 的其他函数。
下面的示例生成 C2134:
// C2134.cpp
// compile with: /c
int A() {
return 42;
};
constexpr int B() {
return A(); // Error C2134: 'A': call does not result in a constant expression.
}
可能的解决方法:
// C2134b.cpp
constexpr int A() { // add constexpr to A, since it meets the requirements of constexpr.
return 42;
};
constexpr int B() {
return A(); // No error
}