简单的问题C++
- C/C++ code
#include <cmath>template <class T> void merge(T a[],int k,int n){ int s=(int)sqrt(n); int j=task1(a,k,n,s); eqexch(a,k-s,j,n-j); int bfs=k-s,bft=k-1; int ds=j-(j-k)%s,dt=j-1; task2(a,n,ds,dt); task3(a,k,n,s,bfs,bft); maintask(a,k,n,s,bfs,ds);}错误:
ogrammint pearls\largemove\largemove\cachemove.h(141): error C2668: 'sqrt' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 10.0\vc\include\math.h(589): could be 'long double sqrt(long double)'
1> c:\program files\microsoft visual studio 10.0\vc\include\math.h(541): or 'float sqrt(float)'
1> c:\program files\microsoft visual studio 10.0\vc\include\math.h(127): or 'double sqrt(double)'
1> while trying to match the argument list '(int)'
1> d:\projects\programmint pearls\largemove\largemove\cachemove.cpp(13) : see reference to function template instantiation 'void merge<int>(T [],int,int)' being compi
[解决办法]
int s=(int)sqrt(n);
对n做个转型吧。转型为float,double都可以
[解决办法]
因为就没有定义参数是int的sqrt函数