Ik heb een vector die objecten van het type Punt bevatten, Punt is een klasse die als instantie variabelen x en y hebben. Nu steek ik in mijn vector enkele van deze Punt objecten en de bedoeling is dat ik volgens een gedefinieerde operator deze vector ga sorteren. Ik heb al veel dingen opgezocht en ben tot de volgende code gekomen maar ik krijg steeds compiling errors.
Heb al veel geprobeert, maar niets hielp, wie kan er mij zeggen wat er eigenlijk scheelt?
Dit zijn de errors die ik krijg, ik gebruik DevC++:
J:\C++\les4oef2.cpp In member function `bool Punt:: operator==(const Punt&) const':
35 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getX()' discards qualifiers
35 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getY()' discards qualifiers
J:\C++\les4oef2.cpp In member function `bool Punt:: operator<(const Punt&) const':
46 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getX()' discards qualifiers
46 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getY()' discards qualifiers
Dank bij voorbaat
Heb al veel geprobeert, maar niets hielp, wie kan er mij zeggen wat er eigenlijk scheelt?
Code:
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
using namespace std;
class Punt
{
private:
int x;
int y;
public:
Punt(int a, int b)
{
this->x = a;
this->y = b;
}
Punt()
{
}
int getX(){
return this->x;
}
int getY(){
return this->y;
}
bool operator==(const Punt &b) const
{ bool temp = false;
if((x == b.getX()) && (y == b.getY()))
{
temp = true;
}
return temp;
}
bool operator<(const Punt &b) const
{
bool temp = false;
if((x == b.getX()) && (y < b.getY()))
{
temp = true;
}
return temp;
}
};
int main(){
int x;
int y;
cout <<"Geef X coordinaat: "<<endl;
cin >> x;
cout <<"Geef Y coordinaat: "<<endl;
cin >> y;
vector<Punt> punten;
while (!cin.fail()){
Punt temp(x,y);
punten.push_back(temp);
cout <<"Geef X coordinaat: "<<endl;
cin >> x;
cout <<"Geef Y coordinaat: "<<endl;
cin >> y;
}
sort(punten.begin(),punten.end());
}
Dit zijn de errors die ik krijg, ik gebruik DevC++:
J:\C++\les4oef2.cpp In member function `bool Punt:: operator==(const Punt&) const':
35 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getX()' discards qualifiers
35 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getY()' discards qualifiers
J:\C++\les4oef2.cpp In member function `bool Punt:: operator<(const Punt&) const':
46 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getX()' discards qualifiers
46 J:\C++\les4oef2.cpp passing `const Punt' as `this' argument of `int Punt::getY()' discards qualifiers
Dank bij voorbaat
Laatst bewerkt: