小编bug*_*001的帖子

C++ 中的 constexpr int 和 constexpr double

我遇到了一个奇怪的案例。

// 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工作?

c++ double integer constexpr c++11

7
推荐指数
1
解决办法
744
查看次数

标签 统计

c++ ×1

c++11 ×1

constexpr ×1

double ×1

integer ×1