gpt4 book ai didi

c++ - MSVC 2015 无法编译 constexpratan

转载 作者:行者123 更新时间:2023-11-28 02:04:47 25 4
gpt4 key购买 nike

我在我的项目中使用了Mingw-w64 编译器。现在我正在使用 MSVC2015 编译项目。以下行给出错误:

constexpr double pi = 4*std::atan(1);

错误:

error: C2131: expression did not evaluate to a constant

但是在mingw中编译没有任何问题。

最佳答案

MSVC 在这种情况下是正确的,来自 [constexpr.functions]p1

This document explicitly requires that certain standard library functions are constexpr. An implementation shall not declare any standard library function signature as constexpr except for those where it is explicitly required.

正如您从我突出显示的最后一句话中看到的那样,如果标准没有这样说,则不允许实现声明函数 constexpr

现在标准说 atanconstexpr 吗?没有,从[c.math]中的签名可以看出:

float atan(float x);  // see [library.c]
double atan(double x);

关于c++ - MSVC 2015 无法编译 constexpratan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37952267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com