隨着4.2.1 G ++編譯器,我得到以下錯誤:C++ CMATH戰俘存在於舊版本的編譯器,而不是在錯誤的較新的一個
functions.cpp:24: error: call of overloaded ‘pow(long int&, 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:373: note: long double std::pow(long double, int)
/usr/include/c++/4.2.1/cmath:369: note: float std::pow(float, int)
/usr/include/c++/4.2.1/cmath:365: note: double std::pow(double, int)
/usr/include/c++/4.2.1/cmath:361: note: long double std::pow(long double, long double)
/usr/include/c++/4.2.1/cmath:357: note: float std::pow(float, float)
這裏的負責代碼:
long power(long a, long b) {
if (b < 0) return 0;
return pow(a,b);
}
但是,在我的4.6.1版本中,我沒有錯誤,也沒有警告我的代碼,我使用兩個long
進行pow評估(即使使用-Wextra標誌)。 這是爲什麼?並且在使用pow
函數時使用了兩個長整數是我的錯誤?
看起來像4.6添加了'pow(long,long)'作爲擴展 – Anycorn 2012-02-14 09:00:36
標準說它應該是double http://pubs.opengroup.org/onlinepubs/9699919799/functions/pow.html所以我認爲as只要你堅持這個標準,你就可以做演員。 – INS 2012-02-14 09:01:00
Anycorn,你能否提供一個參考(把它作爲答案) – 2012-02-14 09:02:13