首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

简单的有关问题C++

2012-04-17 
简单的问题C++C/C++ code#include cmathtemplate class T void merge(T a[],int k,int n){int s(int)

简单的问题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函数

探讨

OK了,为什么呢?

热点排行