error C2668: 'sqrt' : ambiguous call to overloaded function

分析:

模棱两可的函数调用,(在oj上提交会编译出错)

  • Compile Error
Main.cpp
F:\temp\19889863.2398\Main.cpp(21) : error C2668: 'sqrt' : ambiguous call to overloaded function
        math.h(581): could be 'long double sqrt(long double)'
        math.h(533): or       'float sqrt(float)'
        math.h(128): or       'double sqrt(double)'
        while trying to match the argument list '(int)'

系统分不清该是哪种类型的数据

解决办法:

在sqrt括号里面加强制转换类型,

如:

double Distance(node a,node b)
{
	return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

猜你喜欢

转载自blog.csdn.net/qq_41325698/article/details/88382911