Klasse geht nicht
-
#include <iostream> #include <string> using namespace std; class Konto { private: unsigned long Nummer; string Inhaber; double Stand; public: bool Erstelle(const &string, unsigned long, double); void Anzeigen(); }; bool Konto::Erstelle(const string &I_Inhaber, unsigned long I_Nummer, double I_Stand) { Nummer = I_Nummer; Inhaber = I_Inhaber; Stand = I_Stand; return true; } void Konto::Anzeigen() { cout << Nummer << endl; cout << Inhaber << endl; cout << Stand << endl; } int main() { return 0; }
Hi,
Hab nochnix in der main() Funktion
Soll sich erstmal kompilieren lassen. Weiss nicht was daran falsch ist. 1 Fehler: see declaration of 'Konto'. Wie kann ich das beheben?
-
Ändere:
bool Erstelle(const &string, unsigned long, double);
zu
bool Erstelle(const string&, unsigned long, double);Gruß Mirauder Mo
-
Na, vergleich mal die Argumentlisten der Methode Erstelle() bei der Deklaration und Definition.
btw, befass dich am besten außerdem mal mit Konstruktoren.
-
Ich weiss ja was Konstruktoren sind, und wie man sie anwendet. Ist etwas ähnliches wie eine Funktion, und hat den selben namen wie die Klasse.
Das sollte aber ohne Konstruktor sein.
EDIT: Wie wirr
-
Serious - Tobi schrieb:
Das sollte aber ohne Konstruktor sein.
Und damit ist es Blödsinn
-
Ist das, was ich da hab Standard C++?
Mit G++ unter Linux lässt es sich nicht Kompilieren!
-
Wenn du den einen Syntaxfehler rausmachst, ist es OK
dann lässt es sich auch mit dem g++ kompilieren
-
Ja ist es, sag mal was du für nen Fehler bekommst.
MfG Max
-
Gewaltig
if g++ -DHAVE_CONFIG_H -I. -I. -I.. -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -pedantic -W -Wpointer-arith -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -O2 -O0 -g3 -Wall -fno-exceptions -fno-check-new -MT main.o -MD -MP -MF ".deps/main.Tpo" \ -c -o main.o `test -f 'main.cpp' || echo './'`main.cpp; \ then mv -f ".deps/main.Tpo" ".deps/main.Po"; \ else rm -f ".deps/main.Tpo"; exit 1; \ fi main.cpp:8: error: stray '\240' in program main.cpp:8: error: stray '\240' in program main.cpp:8: error: stray '\240' in program main.cpp:8: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:9: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:10: error: stray '\240' in program main.cpp:12: error: stray '\240' in program main.cpp:12: error: stray '\240' in program main.cpp:13: error: stray '\240' in program main.cpp:13: error: stray '\240' in program main.cpp: In member function `bool Konto::Erstelle(const std::string&, long unsigned int, double)': main.cpp:18: error: stray '\240' in program main.cpp:18: error: stray '\240' in program main.cpp:18: error: stray '\240' in program main.cpp:18: error: stray '\240' in program main.cpp:19: error: stray '\240' in program main.cpp:19: error: stray '\240' in program main.cpp:19: error: stray '\240' in program main.cpp:19: error: stray '\240' in program main.cpp:20: error: stray '\240' in program main.cpp:20: error: stray '\240' in program main.cpp:20: error: stray '\240' in program main.cpp:20: error: stray '\240' in program main.cpp:20: error: stray '\240' in program main.cpp:21: error: stray '\240' in program main.cpp:21: error: stray '\240' in program main.cpp: In member function `void Konto::Anzeigen()': main.cpp:26: error: stray '\240' in program main.cpp:26: error: stray '\240' in program main.cpp:26: error: stray '\240' in program main.cpp:26: error: stray '\240' in program main.cpp:27: error: stray '\240' in program main.cpp:27: error: stray '\240' in program main.cpp:27: error: stray '\240' in program main.cpp:28: error: stray '\240' in program main.cpp:28: error: stray '\240' in program main.cpp:28: error: stray '\240' in program main.cpp:28: error: stray '\240' in program main.cpp: In function `int main()': main.cpp:34: error: stray '\240' in program main.cpp:34: error: stray '\240' in program main.cpp:35:2: Warnung: no newline at end of file gmake: *** [main.o] Fehler 1 *** fehlgeschlagen ***
Edit 1: [ cpp ] statt [ / code ]
Edit 2: Hab den falschen Code (den mit dem const& string) genommen.
-
tja, das passiert wenn man copy&paste macht - oder einen sehr exotischen editor verwendet.
anscheinend hast du statt leerzeichen (oder tabs) das Zeichen \240 im Code stehen - und da beschwert sich der Compiler...
-
Hab mir mal die Mühe gemacht, und es von Hand abgetippt, und es geht
Ich verwende KDevelop.