プログラムに取り組んでいますが、コードの 1 行で問題が発生しています。ここの誰かがこの1行のコードを修正する方法を知っているのではないかと思っていました:
long long x;
srand(time(NULL));
x = rand() % 1000;
long long range = pow (2, 60*(pow(2,x)-1)) ;
これを実行するたびに、オーバーロードがあいまいな呼び出しがあるというエラーが表示されます。私はいくつかの調査を行いましたが、それはさまざまなタイプに関係しているようです( に関してlong long
)。この問題を回避するために、これを別の方法でキャストする方法があるのではないかと考えていましたが、これを行う方法がわかりません。2行目のコードを機能させるために何をすべきかについて誰か提案がありますか?
編集:次のエラーが表示されます。
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)
ルシアンが提案した方法では、次のエラーが表示されます。
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)