Compiler fehler bei eclipse
-
bool CTeam::operator< (const CTeam& rop){ if(this->getTotalPoints()>rop->getTotalPoints()){ return true; } if(this->getTotalPoints()== rop.getTotalPoints()){ int Team1Points = this->m_goalsScoredTotal - this->m_goalsReceivedTotal; int Team2Points = rop.m_goalsScoredTotal - rop.m_goalsReceivedTotal; if(Team1Points>Team2Points){ return true; } else{ return false; } }
Bekomme diese Fehler nicht weg ?Bekomme folgende Fehlerescription Resource Path Location Type
base operand of '->' has non-pointer type 'const CTeam' CTeam.cpp /CTeam line 70 C/C++ Problem
Description Resource Path Location Type
passing 'const CTeam' as 'this' argument discards qualifiers [-fpermissive] CTeam.cpp /CTeam line 74 C/C++ ProblemBitte um hilfe
Header sieht so aus:
#ifndef CTEAM_H_ #define CTEAM_H_ #include<iostream> #include<string> using namespace std; class CTeam{ private: string m_teamName; unsigned int m_winsTotal=0; unsigned int m_lostTotal =0; unsigned int m_equalTotal= 0; unsigned int m_goalsScoredTotal = 0; unsigned int m_goalsReceivedTotal=0; public: CTeam(string name = "NoName"); string getName(); void addResult(unsigned int goalsScored,unsigned int goalsReceived); unsigned int const getTotalPoints(); friend ostream& operator<<(ostream& out,CTeam const& rop); bool operator< (const CTeam& rop); }; ostream& operator <<(ostream& out,CTeam const& rop); #endif /* CTEAM_H_ */
Edit durch Arcoth: Code-Tags repariert.
-
sorry cpp vergessen
[code="cpp"bool CTeam::operator< (const CTeam& rop){
if(this->getTotalPoints()>rop->getTotalPoints()){return true;
}
if(this->getTotalPoints()== rop.getTotalPoints()){int Team1Points = this->m_goalsScoredTotal - this->m_goalsReceivedTotal;
int Team2Points = rop.m_goalsScoredTotal - rop.m_goalsReceivedTotal;if(Team1Points>Team2Points){
return true;
}
else{return false;
}}[/code]
-
Ist das jetzt das Gespenst der Digitalisierung?
Gott sei uns gnädig
-
Weißt du wo der Fehler liegt , damit der Compiler das schluckt ?
-
Ja!
bool CTeam::operator< (const CTeam& rop){ if(this->getTotalPoints()>rop->getTotalPoints()){ // <-- Fehler return true; } // ... }
Schau dir diese Zeile genau an (im Vergleich zu den folgenden Zeilen).
-
Wenn ich this. Und rop.
schreibe , geht der Fehler auch nicht weg ?
-
Du hast da zwei Probleme:
class foo{ public: void a(){} void b() const {} // const member function! }; void func(const foo& f) { f->a(); // geht nicht. f ist kein Zeiger. f.a(); // geht auch nicht. a ist nicht const (aber f ist const foo&) f.b(); // ok } int main() { foo f; func(f); }
Der Fehler in Z. 8 ist offensichtlich.
Der andere Fehler ist etwas subtiler und hängt mit der sog. const correctness zusammen.Ich traue mir nicht zu, Dir const correctness zu erklären.
-
Ich komme ehrlich gesagt auch trotzdem nicht auf den Fehler .
Zu schwer für mich