Borland C++ BuilderX mekert meine Konstrucktoren an
-
Hi,
ich hab den Borland C++ BuilderX und hab vor ein etwas längeres Prog zu schreiben.
Ich habe mehrere klassen und habe zu denen Konstrucktoren geschrieben. z.B.:class UBoot : public ship { public: UBoot(); UBoot(int, int); ~UBoot(); void TorpLaden(); bool Invariants() const; }; UBoot::UBoot() { ASSERT(Invariants()); } UBoot::UBoot(int x = 0, int y = 0): ship(x, y) { ASSERT(Invariants()); }
die klasse ship existiert, die anderen funktionen sind auch deklariert. Das Makro ASSERT ist ebenfalls deklariert.
Ich weiß nicht was ich machen soll.
Ein Update des compiler hab ich nich gefunden. ich arbeite mit Version:1.0.0.1786
Mfg Yazoo
-
Und wie sieht die Fehlermeldung aus, die der Compiler dir entgegenwirft?
(auf anhieb sehe ich nur zwei mögliche Fehlerquellen: (a) der (int,int)-Ctor mit Default-Parametern kollidiert mit dem Default-Ctor (d.h. der Compiler weiß nicht, mit welchem ein uboot anlegen soll, wenn du keine Parameter mitgibst) und (b) die Klasse ship braucht einen erreichbaren Default-Ctor, damit dein Ctor arbeiten kann)
-
ich hab ma was ausprobiert indem ich die angemeckerte stelle aus kommentiert hab un dann meckert er mir die nächste funktion an, immer mit der gleichen fehlermeldung(nur andere zeile):
"data.cpp": E2090 Qualifizierer 'UBoot' ist kein Name einer Klasse oder einer Struktur in Zeile 416
und
"data.cpp": E2040 Deklaration nicht ordnungsgemäß abgeschlossen in Zeile 416
-
CStoll schrieb:
Und wie sieht die Fehlermeldung aus, die der Compiler dir entgegenwirft?
(auf anhieb sehe ich nur zwei mögliche Fehlerquellen: (a) der (int,int)-Ctor mit Default-Parametern kollidiert mit dem Default-Ctor (d.h. der Compiler weiß nicht, mit welchem ein uboot anlegen soll, wenn du keine Parameter mitgibst) und (b) die Klasse ship braucht einen erreichbaren Default-Ctor, damit dein Ctor arbeiten kann)
ship besitzt einen default Ctor
-
ich glaube nich mehr das es am compiler liegt, denn ich habe den code auch in nem anderen compiler getestet, hat au net gefuntzt.
das hier is der kommplette code:#include <iostream> using namespace std; enum RICHTUNG { Nord, Sued, West, Ost }; enum LEVEL { NONE, LOW, MEDIUM, HIGH }; #define DEBUGLEVEL HIGH #if DEBUGLEVEL < LOW #define ASSERT(x) #else #define ASSERT(x) \ if (! (x))\ { \ cout <<"FEHLER!! Annahme "<<#x<<" nicht zutreffend\n"; \ cout <<"in Zeile "<<__LINE__<<"\n"; \ cout <<"in Datei "<<__FILE__<<"\n"; \ } #endif #if DEBULEVEL < MEDIUM #define EVAL(x) #else #define EVAL(x) \ cout <<#x<< ":\t" <<x<< endl; #endif #if DEBUGLEVEL < HIGH #define PRINT(x) #else #define PRINT(x) \ cout <<x<< endl; #endif class Koord { public: Koord(); Koord(int, int); ~Koord(); int GetX() const; int GetY() const; void SetX(int); void SetY(int); bool Invariants() const; private: int itsX; int itsY; }; Koord::Koord() { ASSERT(Invariants()); } Koord(int x, int y) { ASSERT(Invariants()); itsX = x; itsY = y; ASSERT(Invariants()); } Koord::~Koord() { ASSERT(Invariants()); } int Koord::GetX() const { ASSERT(Invariants()); return itsX; } int Koord::GetY() const { ASSERT(Invariants()); return itsY; } void Koord::SetX(int x) { ASSERT(Invariants()); itsX = x; ASSERT(Invariants()); } void Koord::SetY(int y) { ASSERT(Invariants()); itsY = y; ASSERT(Invariants()); } bool Koord::Invariants() const { PRINT("...Koord überpfüft..."); return (itsX >= 0); } class Torpedo { public: Torpedo(); Torpedo(int, int); ~Torpedo(); int GetSpeed() const; int GetRichtung() const; int GetXKoord() const; int GetYKoord() const; int GetZiel() const; void SetZiel(int, int); void SetXKoord(int); void SetYKoord(int); void SetRichtung(RICHTUNG); void SetSpeed(int); bool Invariants() const; void Move(); private: int itsSpeed; RICHTUNG itsRichtung; Koord itsKoord; Koord itsZiel; }; Torpedo::Torpedo() { ASSERT(Invariants()); } Torpedo::Torpedo(int x, int y) { ASSERT(Invariants()); itsKoord.SetX(x); itsKoord.SetY(y); ASSERT(Invariants()); } Torpedo::~Torpedo() { ASSERT(Invariants()); } int Torpedo::GetSpeed() const { ASSERT(Invariants()); return itsSpeed; } int Torpedo::GetRichtung() const { ASSERT(Invariants()); return itsRichtung; } int Torpedo::GetXKoord() const { ASSERT(Invariants()); return itsKoord.GetX(); } int Torpedo::GetYKoord() const { ASSERT(Invariants()); return itsKoord.GetY(); } int Torpedo::GetZielX() { ASSERT(Invariants()); return itsZiel.GetX(); } int Torpedo::GetZielY() { ASSERT(Invariants()); return itsZiel.GetY(); } void Torpedo::SetZiel(int x, int y) { ASSERT(Invariants()); itsZiel.SetX = x; itsZiel.SetY = y; ASSERT(Invariants()); } void Torpedo::SetXKoord(int x) { ASSERT(Invariants()); itsKoord.SetX(x); ASSERT(Invariants()); } void Torpedo::SetYKoord(int y) { ASSERT(Invariants()); itsKoord.SetY(y); ASSERT(Invariants()); } void Torpedo::SetRichtung(RICHTUNG richtung) { ASSERT(Invariants()); itsRichtung = richtung; ASSERT(Invariants()); } void Torpedo::SetSpeed(int speed) { ASSERT(Invariants()); itsSpeed = speed; ASSERT(Invariants()); } void Torpedo::Move() {} bool Torpedo::Invariants() const { PRINT("...Torpedo überpfüft..."); return (itsKoord.GetX() >= 0); } class ship { public: ship(); ship(int, int); virtual ~ship(); virtual int GetSpeed() const; virtual int GetRichtung() const; virtual int GetXKoord() const; virtual int GetYKoord() const; virtual void SetXKoord(int); virtual void SetYKoord(int); virtual void SetRichtung(RICHTUNG); virtual void SetSpeed(int); virtual void Move(); virtual void Shoot(); virtual void TorpLaden() = 0; virtual int CheckTorpedo() const; virtual void SetTorp(int x); virtual bool Invariants() const; protected: int itsSpeed; RICHTUNG itsRichtung; Koord itsKoord; Torpedo* itsTorp[25]; }; ship::ship() { ASSERT(Invariants()); } ship::ship(int x, int y) { ASSERT(Invariants()); itsRichtung = Nord; itsKoord.SetX(x); itsKoord.SetY(y); ASSERT(Invariants()); } ship::~ship() { ASSERT(Invariants()); } int ship::GetSpeed() const { ASSERT(Invariants()); return itsSpeed; } int ship::GetRichtung() const { ASSERT(Invariants()); return itsRichtung; } int ship::GetXKoord() const { ASSERT(Invariants()); return itsKoord.GetX(); } int ship::GetYKoord() const { ASSERT(Invariants()); return itsKoord.GetY(); } void ship::SetXKoord(int x) { ASSERT(Invariants()); itsKoord.SetX(x); ASSERT(Invariants()); } void ship::SetYKoord(int y) { ASSERT(Invariants()); itsKoord.SetY(y); ASSERT(Invariants()); } void ship::SetRichtung(RICHTUNG richtung) { ASSERT(Invariants()); itsRichtung = richtung; ASSERT(Invariants()); } void ship::SetSpeed(int speed) { ASSERT(Invariants()); itsSpeed = speed; ASSERT(Invariants()); } void ship::Move() {} void ship::Shoot(RICHTUNG richtung, int speed, int x, int y) { ASSERT(Invariants()); int i = CheckTorpedo(); itsTorp[i].SetRichtung(richtung); itsTorp[i].SetSpeed(speed); itsTorp[i].SetZiel(x, y); ASSERT(Invariants()); } bool ship::Invariants() const { ASSERT(Invariants()); PRINT("...ship überpfüft..."); return (itsKoord.GetX() >= 0); } int ship::CheckTorpedo() const { ASSERT(Invariants()); int i; for(i = 0; i < 25; i++) { if (itsTorp[i] == 0) i=i; else { break; } } return i; } void ship::SetTorp(int x) { ASSERT(Invariants()); delete itsTorp[x]; itsTorp[x] = 0; ASSERT(Invariants()); } class UBoot : public ship { public: UBoot(); UBoot(int, int); ~UBoot(); void TorpLaden(); bool Invariants() const; }; UBoot::UBoot() { ASSERT(Invariants()); } UBoot::UBoot(int x, int y): ship(x, y) { ASSERT(Invariants()); } UBoot::~UBoot() { ASSERT(Invariants()); } void UBoot::TorpLaden() { ASSERT(Invariants()); for(int i = 0; i < 25; i++) { itsTorp[i] = new Torpedo; i++; cout <<"Torpedo "<<i<<" geladen!"; i--; } ASSERT(Invariants()); } bool UBoot::Invariants() const { PRINT("...UBoot überpfüft..."); return (itsKoord.GetX() >= 0); } class Enemy : public ship { public: Enemy(); Enemy(int, int); ~Enemy(); void TorpLaden(); bool Invariants() const; } Enemy::Enemy() { ASSERT(Invariants()); } Enemy::Enemy(int x, int y): ship(x, y) { ASSERT(Invariants()); } Enemy::~Enemy() { ASSERT(Invariants()); } void Enemy::TorpLaden() { ASSERT(Invariants()); for (int i = 0; i < 25; i++) { itsTorp[i] = new Torpedo; } } bool Enemy::Invariants() const { PRINT("...Enemy überpfüft..."); return (itsKoord.GetX() >= 0); } int main() { return 0; }
Ich glaube zwar net dass den iener ganz lesen wird aba es wäre nett denn ich stehe zur zeit komplett aufm schlauch!!!
-
ich habe das prob gelöst: ich habe teiweise denk-fehler gemacht, und teilweise einfach falsch definiert.