为什么sqrt()在智能感知中使用两个pow()的内部计算是错误的

How come sqrt() with which uses a calculation of two pow()'s inside of is wrong in intellisense

本文关键字:pow 两个 内部 错误 计算 智能 sqrt 感知 为什么      更新时间:2023-10-16

我有这样的代码:

int findY ( int x, int r) {
return sqrt(pow(x,2) - pow(r,2));
};

但由于某种原因,智能感知女士将其标记为错误的语法。我不知道为什么。

看看它给出的错误:

1>..main.cpp(7): error C2668: 'pow' : ambiguous call to overloaded function
1>          C:Program Files (x86)Microsoft Visual Studio 10.0VCincludemath.h(583): could be 'long double pow(long double,int)'
1>          C:Program Files (x86)Microsoft Visual Studio 10.0VCincludemath.h(535): or       'float pow(float,int)'
1>          C:Program Files (x86)Microsoft Visual Studio 10.0VCincludemath.h(497): or       'double pow(double,int)'
1>          while trying to match the argument list '(int, int)'

基本上,它是一个模糊的重载。所以你需要强制转换它来澄清:

return sqrt(pow((double)x,2.) - pow(((double)r,2.));

不仅如此,您真的打算将返回类型设置为整型吗?