0

Default sorting by first member variable of class

As class has all the member variables of int type and C++ knows how to sort int types, why can't class sorting work without < operator ? Try uncommening sort statement and it will throw errors In other words , we have vector<vector<int>> , then C++ by default sorts outer vector based on first element of inner vector. Why this non uniformity https://sololearn.com/compiler-playground/cvj2h8MyefIL/?ref=app

12th Dec 2024, 2:10 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Answers
0
maybe because the default behavior is ascending sort, so it needs an overload for < for custom types.
13th Dec 2024, 5:22 AM
Bob_Li
Bob_Li - avatar
0
Let it do ascending or descending. I was expecting it to not ask for any operator like it is not asking for vector of vector.
13th Dec 2024, 2:34 PM
Ketan Lalcheta
Ketan Lalcheta - avatar