为什么编译器在此代码中说POW(N,K)含糊不清
Why does the compiler say pow(n,k) ambiguous in this code?
在xcode 4.5(Mac)下编译以下代码时,汇编失败,以下错误消息:
call to 'pow' is ambiguous
为什么?谢谢!
#include <iostream>
#include <cmath>
#include <limits>
using namespace std;
int main()
{
cout << "tSquare root calculator using an emulation the ENIAC's algorithm." << endl
<< endl;
long long m;
while ((cout << "Enter a positive integer:" << endl)
&& (!(cin >> m) || m < 0 || m > 9999999999)) //10-digit maxium
{
cout << "Out of range.";
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
}
again:
long long l = m;
//Find out how big the integer is and adjust k accordingly.
int order = -1;
long long temp = m;
do
{
temp /= 10;
order++;
} while (temp/10);
int k = order/2;
//Step 1
long long a = -1;
do
{
a+=2;
m -= a*pow(100,k);
} while (m >= 0);
while (k > 0)
{
k--;
//Step 2
if (m < 0)
{
a = 10*a+9;
for (;m < 0;a -= 2)
{
m += a*pow(100,k);
}
a += 2;
}
//Step 3
else
{
a = 10*a-9;
for(;m >= 0;a += 2)
{
m -= a*pow(100,k);
}
a -= 2;
}
}
//Step 4
cout << endl << "The square root of " << l << " is greater than or equal to "
<< (a-1)/2 << " and less than " << (a+1)/2 << "." << endl << endl;
while ((cout << "Enter a positive integer to calculate again, or zero to exit." << endl)
&& (!(cin >> m) || m < 0 || m > 9999999999))
{
cout << "Out of range.";
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
}
if (m > 0) goto again;
return 0;
}
,您可以看到这里没有POW(INT,INT);
pow
<cmath>
double pow ( double base, double exponent );
long double pow ( long double base, long double exponent );
float pow ( float base, float exponent );
double pow ( double base, int exponent );
long double pow ( long double base, int exponent );
此链接看起来像是回答您的问题:http://bytes.com/topic/c/answers/727736-bambigous-call-pow
看起来POW()函数不喜欢整数。
相关文章:
- 子例程,不使用 pow,并带有参数和返回
- 在C++不使用 POW 的情况下处理负指数
- C++在不使用pow或循环的情况下计算一个数字的幂
- Boost::asio::streambuf consumption() 不清空缓冲区
- 使用POW()产生不正确值的立方函数
- 为什么UINT64_T不能正确显示POW(2,64)-1
- 为什么编译器在此代码中说POW(N,K)含糊不清
- 仅使用整数实施POW(X,n)%D.(不利用库功能)
- 为什么我不能以这种方式清空文件?
- 如何清空列表而不破坏其元素
- 为什么我的 pow 方法不起作用?
- 我搞不清我的代码出了什么问题
- “距离”的提法含糊不清
- 我是不是太快了,数不清妖孽
- 对'list'的引用含糊不清
- 为什么这个电话含糊不清
- §9.5/8 中可能含糊不清的陈述
- 口齿不清的类
- 对"class"的提及含糊不清
- 何时不使用pow()