Veröffentlicht 13. Februar 201114 j Hallo leute, ich habe ein Problem bei einem Programm und zwar: bei dieser schleife: while(abs(res2-res)>0.00001) { res2=res; res = (fa(x+h)-fa(x)) / h; h = h / 10; } kommt die Fehlermeldung: call of overloaded `abs(double)' is ambiguous candidates are: int abs(int) long long int __gnu_cxx::abs(long long int) long int std::abs(long int) was sich explizit auf while(abs(res2-res)>0.00001) bezieht... Wäre dieser blöde Fehler nicht würde alles wunderbar funktionieren manno Hier noch der ganze code... #include <cstdlib> #include <iostream> using namespace std; double fa(double x); double fa2(double x); int main() { cout << "x\tf(x)\tf2(x)" << endl; for(double i = -5;i <= 5; i = i + 0.5) { printf("%.2f\t%.2f\t%lf\n",i,fa(i),fa2(i)); } system("PAUSE"); return EXIT_SUCCESS; } double fa(double x) { return x*x; } double fa2(double x) { double res=0,res2=1,h=0.1; while(abs(res2-res)>0.00001) { res2=res; res = (fa(x+h)-fa(x)) / h; h = h / 10; } return res; } Ich hoffe ihr könnt mir schnell weiterhelfen! MfG Artery
13. Februar 201114 j Ich würde sagen, da fehlt #include <cmath> Da sind die std::abs-Überladungen für Fließkommatypen deklariert.
13. Februar 201114 j Autor Omfg so ein doofer flüchtigkeitsfehler... Die Fehleranzeige hatte mich verwirrt, DANKE! flashpixx was bringt mir das bzw. wozu? MfG Artery
13. Februar 201114 j Deine Abbruchbedingung kannst Du passend zu Deinen Datentypen anpassen, im Moment ist der Wert für den Abbruch fest codiert.
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.