I have some problem with sorting my vectors.I want to sort my vectors acording to first element wchich is Number.Can someone explain me what I doing wrong and what this 2 errors means?
I try sort this with compare function and without it and nothing works.
struct Point{
int x;
int y;
};
bool compare(int a,int b){
return a < b;
}
int main()
{
int N,Number,x,y;
cin >> N;
vector<pair<int,Point>> p;
for(int i = 0 ; i < N ; i++){
cin >> Number >> x >> y;
pair<int,Point> pom = {Number,{x,y}};
p.push_back(pom);
}
// sort(p.begin(),p.end());
// sort(p.begin().p.end(),compare);
return 0;
}
I've got two errors but I don't know what means:
1.no match for 'operator<' (operand types are 'const Point' and 'const Point')
|| (!(__y.first < __x.first) && __x.second < __y.second); }
2.body of constexpr function 'constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&) [with _T1 = int; _T2 = Point]' not a return-statement
|| (!(__y.first < __x.first) && __x.second < __y.second); }
^
^
int
s, this is already provided in the language. What compiler doesn't know is how to compare two instances ofPoint
class. Or a comparator forstd::pair<int, Point>
, if you would prefer to use it only in thestd::sort
function (rather than providing anoperator<(Point, Point)
for everyone to use) – Yksisarvinenstd::sort
, then it is expected to returntrue
if elementa
should go before elementb
,false
otherwise. – Yksisarvinen