带有默认参数的函数不能用VC++编译,而是用g ++和clang编译

Reg*_*ett 5 c++ templates

我搜索过这个网站,无法找到问题的解决方案.我尽可能地减少了我的示例代码,同时仍保留相关错误.我留下了以下两个文件:

test.hpp

namespace models {

template<typename FloatingPoint>
class ellipsoid {
  public:
    explicit ellipsoid(FloatingPoint = 6378137.0);
  private:
    FloatingPoint a_;
};

template<typename FloatingPoint>
ellipsoid<FloatingPoint>::ellipsoid(FloatingPoint a) : a_(a) {}

}  // End namespace models


// Function declaration
template<typename FloatingPoint>
FloatingPoint compute(FloatingPoint,
                      const models::ellipsoid<FloatingPoint>& =
                          models::ellipsoid<FloatingPoint>());

// Function definition
template<typename FloatingPoint>
FloatingPoint compute(FloatingPoint x,
                      const models::ellipsoid<FloatingPoint>& model) {

    return 3.14;
}
Run Code Online (Sandbox Code Playgroud)

TEST.CPP

#include "test.hpp"

int main() {
    compute(10.0);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我使用VC++ 2017编译上面的代码时,我收到以下错误:

error C2512: 'models::ellipsoid<FloatingPoint>': no appropriate default constructor available
note: No constructor could take the source type, or constructor overload resolution was ambiguous
Run Code Online (Sandbox Code Playgroud)

clang和g ++都编译没有问题.此外,如果我ellipsoid从命名空间中删除该类models,并删除函数中的models::调用compute,则使用VC++进行编译.这是VC++编译器中的错误,还是我的代码中有错误?

Fed*_*dor 1

这是 VC++ 中的一个错误,自编译器版本 19.23 起已在 Visual Studio 2019 中修复。演示: https: //gcc.godbolt.org/z/a5TxPa8ac