本文介绍了在Windows上为Matlab构建libspline-对重载函数'pow'的歧义调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows上为Matlab构建libspline,可在这里找到:

I'm trying to build libspline for Matlab on Windows, available here:

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行是这样的:

The line 156 in additiveModel.cpp is this:

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

在这里您可以看到传递给pow的两个参数都是int.由于math.h中没有pow的重载会占用两个int,因此,由于最佳可行功能在这种情况下不是唯一的,因此重载解析失败.

Here you can see that both of the arguments that are being passed to pow are ints. Since there is no overload of pow in math.h that would take two ints, the overload resolution fails since the best viable function is not unique in this case.

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

You can fix this by casting the first parameter to a suitable type, such as double:

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

这篇关于在Windows上为Matlab构建libspline-对重载函数'pow'的歧义调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 01:27
查看更多