作者fxxk1234ps (非乡民)
看板EE_DSnP
标题[问题] overloaded pow is ambiguous!?
时间Wed Oct 31 19:56:48 2007
我的程式码如下:
int main()
{
double pi;
double accuracy;
unsigned iteration;
double error = fabs(pi - 3.141592653);
...
for (iteration = 0; error > accuracy; iteration++)
{
pi += (pow (-1, iteration) * 4 / (1 + 2 * iteration));
};
...
}
在黄色这行出现错误
call of overloaded 'pow(int, unsigned int&)' is ambiguous
没学过overload...囧 卡关了XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.236.68
1F:推 ric2k1:pow(-1.0, iteration) 10/31 20:18
2F:推 ilway25:unsigned int & iteration = 0 ?? 我怀疑啦没试过 10/31 20:26
3F:推 fxxk1234ps:不论改成-1.0或把iteration改成int都还是ambiguous... 10/31 22:46
4F:推 ric2k1:compile 的 error message 其实有说明, 试着看懂一下... 10/31 23:11
5F:→ ric2k1:try pow(-1.0, int(iteration)) 10/31 23:12
6F:推 fxxk1234ps:compile过了^^ 但是运算好慢...答案都出不来 11/01 20:29
7F:推 ric2k1:想一下, 重复的运算太多了... 11/01 21:10
8F:→ ric2k1:可以与我的 ref program 比较一下. 11/01 21:11