Tôi có C++ mã sau:quá tải gọi mơ hồ để abs (double)
#include <math.h>
#include <cmath.h> // per http://www.cplusplus.com/reference/clibrary/cmath/abs/
// snip ...
if ((loan_balance < 0) && (abs(loan_balance) > loan_payment)) {
...
}
và make
thổi lên trên:
error: call of overloaded 'abs(double)' is ambiguous
cũng quan tâm:
/usr/include/stdlib.h:785: note: candidates are: int abs(int)
Làm thế nào tôi có thể chỉ định rằng trình biên dịch cần phải gọi abs() trong cmath.h có thể xử lý nổi?
thông tin Compiler (Không chắc chắn nếu vấn đề này):
[[email protected]_box ~/some_code]# gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr /share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)
Trang cplusplus bạn trích dẫn không nói để bao gồm cmath.h. Nó nói cmath. Đó là phiên bản C++ của math.h. Không bao gồm cả hai. –