我遇到了一个奇怪的案例。
// this does not work, and reports:
// constexpr variable 'b' must be initialized by a constant expression
int main() {
const double a = 1.0;
constexpr double b = a;
std::cout << b << std::endl;
}
// this works...
int main() {
const int a = 1;
constexpr int b = a;
std::cout << b << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
有什么特别之处double所以它不能constexpr工作?