在一个程序上工作,我的一行代码给我带来了问题。我想知道这里是否有人可能知道如何修复这一行代码:
long long x;
srand(time(NULL));
x = rand() % 1000;
long long range = pow (2, 60*(pow(2,x)-1)) ;
每当我运行它时,我都会收到一条错误消息,指出存在对重载的模棱两可的调用。我做了一些研究,它似乎与不同的类型有关(关于long long
)。我在想可能有一种方法可以用不同的方式来解决这个问题,但是我不确定如何做到这一点。有人会碰巧对如何使第二行代码正常工作有任何建议吗?
编辑:我收到以下错误:
main1.cpp:149: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
/usr/include/architecture/i386/math.h:343: note: candidate 1: double pow(double, double)
/usr/include/c++/4.2.1/cmath:357: note: candidate 2: float std::pow(float, float)
main1.cpp:149: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
/usr/include/architecture/i386/math.h:343: note: candidate 1: double pow(double, double)
/usr/include/c++/4.2.1/cmath:357: note: candidate 2: float std::pow(float, float)
使用Luchian建议的方法出现以下错误如下:
main1.cpp:149: error: call of overloaded 'pow(int, long long int&)' is ambiguous
/usr/include/architecture/i386/math.h:343: note: candidates are: double pow(double, double)
/usr/include/c++/4.2.1/cmath:357: note: float std::pow(float, float)
/usr/include/c++/4.2.1/cmath:361: note: long double std::pow(long double, long double)
/usr/include/c++/4.2.1/cmath:365: note: double std::pow(double, int)
/usr/include/c++/4.2.1/cmath:369: note: float std::pow(float, int)
/usr/include/c++/4.2.1/cmath:373: note: long double std::pow(long double, int)