Fehlermeldung
-
Hallo möchte keine frage zur Aufgabenstellung beantwortet haben .
Wäre nur schön wenn mir jemand sagen wie ich die Fehlermeldungen weg bekommen.Es ist nur ne Übungsaufgabe . Wollte das nur sicherheitshalber sagen ,da sonst meistens niemand helfen will
Header war vorgegeben nach klassendiagramm:
#ifndef CTEAM_H_ #define CTEAM_H_ #include<iostream> #include<string> class CTeam{ private: std::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(std::string name = "NoName"); std::string getName(); void addResult(unsigned int goalsScored,unsigned int goalsReceived); unsigned int const getTotalPoints(); friend std::ostream& operator<< (std::ostream& out, CTeam const& rop); bool operator< (CTeam const& rop ); }; std::ostream& operator<< (std::ostream& out, CTeam const& rop);``` ```cpp #include"CTeam.h" #include<iostream> using namespace std; CTeam::CTeam(std::string name ){ m_teamName = name; } std::string CTeam::getName(){ return m_teamName; } void CTeam::addResult(unsigned int goalsScored,unsigned int goalsReceived){ if(goalsScored > goalsReceived) { m_winsTotal += 1; m_goalsScoredTotal += goalsScored; m_goalsReceivedTotal += goalsReceived; } if(goalsScored > goalsReceived) { m_lostTotal +=1; m_goalsReceivedTotal += goalsReceived; m_goalsScoredTotal += goalsScored; } if( goalsScored== goalsReceived) { m_equalTotal += 1; m_goalsScoredTotal += goalsScored; m_goalsReceivedTotal += goalsReceived; } } unsigned int const CTeam::getTotalPoints() { return 3*m_winsTotal+1*m_equalTotal; } ostream& operator<<(ostream& out,CTeam const& rop){ out << rop.m_teamName << ":" << "" << rop.m_winsTotal << rop.m_equalTotal<< rop.m_lostTotal<<" (" << 3*rop.m_winsTotal+1*rop.m_equalTotal<< "Punkte )" << " " <<"Tore"<<rop.m_goalsScoredTotal<<":"<<rop.m_goalsReceivedTotal<<endl; return out; } bool CTeam::operator< (CTeam const& rop ){ if(this.getTotalPoints()>rop.getTotalPoints()){ return true; } else{ return false; } 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 Fehlermeldungen bei bool operator Methode.
Description Resource Path Location Type
'this' argument to member function 'getTotalPoints' has type 'const CTeam', but function is not marked const CTeam.cpp /Team SS13 line 70 C/C++ ProblemDescription Resource Path Location Type
Invalid arguments '
Candidates are:
const unsigned int getTotalPoints()
' CTeam.cpp /Team SS13 line 71 Semantic ErrorDescription Resource Path Location Type
Invalid arguments '
Candidates are:
const unsigned int getTotalPoints()
' CTeam.cpp /Team SS13 line 80 Semantic ErrorDescription Resource Path Location Type
member reference type 'const CTeam *' is a pointer; did you mean to use '->'? CTeam.cpp /Team SS13 line 70 C/C++ ProblemBitte um Hilfe
-
unsigned int const CTeam::getTotalPoints()
sollte
const
sein:unsigned int const CTeam::getTotalPoints() const
Das
const
nachunsigned int
ist für die Katz'.bool CTeam::operator< (CTeam const& rop ){ if(this.getTotalPoints()>rop.getTotalPoints()){ return true; } else{ return false; } if(this->getTotalPoints()== rop.getTotalPoints()){ // das
wird nie erreicht werden.
-
Die Aufgabe war so :
Zum Vergleich der Tabellenplätze implementieren Sie den überladenen Operator <, der true zurückgibt, wenn das Team des linken Operanden besser ist als das Team des rechten,
also einen kleineren Tabellenplatz erhält. Er ist wie folgt spezifiziert:
Es wird true zurückgegeben, wenn der linke Operand mehr Punkte hat als der rechte Operand.
Bei gleich vielen Punkten entscheidet die Tordifferenz (Gesamtzahl eigener Tore – Gesamtzahl Gegentore). Wenn der linke Operand eine bessere (höhere) Tordifferenz hat als der rechte, wird ebenfalls true zurückgegeben.
In allen anderen Fällen wird false zurückgegeben.Fehler bleiben allerdings siehe Bild:
https://picload.org/view/dciliwia/bildschirmfoto2019-01-19um13.3.png.html
unsigned int CTeam::getTotalPoints const() { return 3*m_winsTotal+1*m_equalTotal; } ostream& operator<<(ostream& out,CTeam const& rop){ out << rop.m_teamName << ":" << "" << rop.m_winsTotal << rop.m_equalTotal<< rop.m_lostTotal<<" (" << 3*rop.m_winsTotal+1*rop.m_equalTotal<< "Punkte )" << " " <<"Tore"<<rop.m_goalsScoredTotal<<":"<<rop.m_goalsReceivedTotal<<endl; return out; } bool CTeam::operator< (CTeam const& rop ){ if(this.getTotalPoints()>rop.getTotalPoints()){ return true; } else{ return false; } 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; } } }
Das ich das const bei der get Funktion verschoben habe zeigt bei mir auch Fehler an?
-
#include"CTeam.h" #include<iostream> using namespace std; CTeam::CTeam(std::string name ){ m_teamName = name; } std::string CTeam::getName(){ return m_teamName; } void CTeam::addResult(unsigned int goalsScored,unsigned int goalsReceived){ if(goalsScored > goalsReceived) { m_winsTotal += 1; m_goalsScoredTotal += goalsScored; m_goalsReceivedTotal += goalsReceived; } if(goalsScored > goalsReceived) { m_lostTotal +=1; m_goalsReceivedTotal += goalsReceived; m_goalsScoredTotal += goalsScored; } if( goalsScored== goalsReceived) { m_equalTotal += 1; m_goalsScoredTotal += goalsScored; m_goalsReceivedTotal += goalsReceived; } } unsigned int CTeam::getTotalPoints() const{ return 3*m_winsTotal+1*m_equalTotal; } ostream& operator<<(ostream& out,CTeam const& rop){ out << rop.m_teamName << ":" << "" << rop.m_winsTotal << rop.m_equalTotal<< rop.m_lostTotal<<" (" << 3*rop.m_winsTotal+1*rop.m_equalTotal<< "Punkte )" << " " <<"Tore"<<rop.m_goalsScoredTotal<<":"<<rop.m_goalsReceivedTotal<<endl; return out; } bool CTeam::operator< (CTeam const& rop ){ if(this->getTotalPoints()>rop.getTotalPoints()){ return true; } else{ return false; } 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; } } }
Habe jetzt die Fehler beseitigt
Passt es so?
-
@Programmer33 sagte in Fehlermeldung:
Passt es so?
Keine Ahnung? Tut es für Testfälle laut der Aufgabenbeschreibung das, was es soll? Wenn ja dann passt es wohl?
Nebenbei 1 * x = x.
-
@Programmer33 Das zweite if in operator< wird immer noch nicht erreicht.
Edit: Wenn Warnings angeschaltet sind müsste der compiler eigentlich meckern.
-
ja warnungen bekomme ich :
Description Resource Path Location Type
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CTeam.h /Team SS13 line 17 C/C++ Problem
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CTeam.h /Team SS13 line 18 C/C++ Problem
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CTeam.h /Team SS13 line 19 C/C++ Problem
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CTeam.h /Team SS13 line 20 C/C++ Problem
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CTeam.h /Team SS13 line 21 C/C++ ProblemAber wieso wird das 2te if nicht erreicht ? Verstehe es nicht
-
@Programmer33 erstes if:
wenn ... return true;
ansonsten return false;weiter gehts dann nicht....
return beendet eine funktion....
-
Du mußt beim
else
-Zweig auf<
abfragen (und dann kann die folgende Abfrage auf==
entfallen).
-
@Programmer33 sagte in Fehlermeldung:
in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] CTeam.h /Team SS13 line 17 C/C++ Problem
Du mußt für initialisierungen a la
struct foo { int bar = 42; };
deinem Compiler sagen, daß es sich um C++11 oder später handelt. Für
gcc
undclang
:--std=c++11
.
-
Ja aber in der Aufgabe steht doch return true zurück zu geben ?
Oder verstehe ich die Aufgabe falsch?
-
@Programmer33 Ja, aber wie @Swordfish schon schrieb. Der untere Code ist tot. Bis dahin kommt die Funktion erst gar nicht.... Sie ist nach dem ersten if zuende. Zum 2. kommts erst garnet
-
Aha ok jetzt verstehe ich es :).
Wie soll ich es dann machen ?
-
@Programmer33 sagte in Fehlermeldung:
Wie soll ich es dann machen ?
Anders.
Was erwartest du? Du zeigst weder vollständigen Code noch die vollständige Aufgabenstellung.
-
https://picload.org/view/dcilpoic/bildschirmfoto2019-01-19um17.0.png.html
https://picload.org/view/dcilpoil/bildschirmfoto2019-01-19um17.0.png.htmlDie Aufgabenstellung ist in den Links .
Der code ist vollständig
-
@Programmer33 Th69 hat doch den richtigen Tipp gegeben. Man kann if/else auch verschachteln:
if (wenn das) { tue das; return bar; // funktion endet hier } else if (oder jenes) { tue jenes; return bar; // funktion endet hier } else { ansonsten mach dies; return bar; // funktion endet hier }
den letzten else kannst du auch weglassen und den rest direkt drunter schreiben. Ist Geschmackssache...
if (wenn das) { tue das; return foo; // funktion endet hier } else if (oder jenes) { tue jenes; return bar; //funktion endet hier } ansonsten mach dies; return bar; // funktion endet hier
-
@Programmer33 sagte in Fehlermeldung:
https://picload.org/view/dcilpoic/bildschirmfoto2019-01-19um17.0.png.html
https://picload.org/view/dcilpoil/bildschirmfoto2019-01-19um17.0.png.html
Die Aufgabenstellung ist in den Links .Du bitte nix posten Bilder mit Text. Wenn Text du bitte posten Text. Danke.
Der code ist vollständig
Nope.
-
Wenn du eine Ausbildung zum Anwendungsentwickler machst solltest du unbedingt selbst Geld in Bücher investieren. In der Ausbildung gibt's nur das nötigste. Ich empfehle dir „Der C++-Programmierer“ von Prof. Dr. Ullrich Breymann aus dem Hanser-Verlag. Aktuell zu C++17. Oder was auf englisch wenn du da richtig fit bist. Du tust dir selbst einen Gefallen damit (Und Hernn Breymann)
Nein, ich bekomme keine Provision. Das Buch hat hier einen guten Ruf.
hth