c++ - 在 Windows 上为 Matlab 构建 libspline - 对重载函数 'pow' 的不明确调用

标签 c++ visual-studio matlab overload-resolution

我正在尝试为 Windows 上的 Matlab 构建 libspline,可在此处获取:

http://ttic.uchicago.edu/~smaji/projects/libspline-release1.0.tar.gz

我收到以下错误:

>> make
additiveModel.cpp 
additiveModel.cpp(156) : error C2668: 'pow' : ambiguous call to overloaded function 
        C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\math.h(583): could be 'long double pow(long double,int)' 
        C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\math.h(535): or       'float pow(float,int)' 
        C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\math.h(497): or       'double pow(double,int)' 
        while trying to match the argument list '(int, int)' 

  C:\USR\ML\MATLAB~1\BIN\MEX.PL: Error: Compile of 'additiveModel.cpp' failed. 

??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> make at 4
mex -O -largeArrayDims -c additiveModel.cpp

如何解决?

最佳答案

additiveModel.cpp 中的第 156 行是这样的:

dimwts[2*i] = 1.0/pow(i+1,reg);

在这里您可以看到传递给 pow 的两个参数是int s。由于pow没有过载在math.h这需要两个int s,重载决策失败,因为在这种情况下最佳可行函数不是唯一的。

您可以通过将第一个参数转换为合适的类型来解决此问题,例如 double :

dimwts[2*i] = 1.0/pow(static_cast<double>(i+1),reg);

关于c++ - 在 Windows 上为 Matlab 构建 libspline - 对重载函数 'pow' 的不明确调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17633970/

相关文章:

python - 从 numpy 数组获取指针以将图像发送到 C++

asp.net - 在 VS 中附加到工作进程的更快方法

algorithm - 如何在 MATLAB 中检测几乎重叠的圆形对象?

使用 GUIDE : Want to dynamically update graphs 的 Matlab GUI

c++ - 具有自动处理列宽的表格输出库?

C++隐藏继承类?

c++在子类的父类中设置指针变量并在父类中使用它

visual-studio - Visual Studio 2019 CE Powershell 项目

c# - 使用改变环境的代码进行单元测试的实用方法

python - OpenCV相机标定,无法控制畸变常数