मैं निम्नलिखित सी ++ कोड है:अस्पष्ट अधिभार कॉल
#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)) {
...
}
और ऊपर पर make
चल रही है:
error: call of overloaded 'abs(double)' is ambiguous
भी ब्याज की
:
/usr/include/stdlib.h:785: note: candidates are: int abs(int)
मैं कैसे निर्दिष्ट कर सकता हूं कि कंपाइलर को absath.h में cmath.h में कॉल करने की आवश्यकता है जो फ्लोट को संभाल सकता है?
संकलक की जानकारी (सुनिश्चित नहीं हैं कि अगर यह मायने रखती है):
[[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)
आपके द्वारा उद्धृत cplusplus पृष्ठ cmath.h शामिल नहीं कहता है। यह cmath कहते हैं। वह math.h का C++ संस्करण है। दोनों शामिल न करें। –