struct Account
{
int Position;
string Name;
int Score;
string Date;
int Level;
booloperator < (User SOMETHING, User SOMETHING)
{
return (SOMETHING < SOMETHING);
}
};
vector<Account> User;
User.push_back(Account());
User.push_back(Account());
User.push_back(Account());
User[0].Position=1;
User[1].Position=2;
User[2].Position=3;
sort(User.begin(), User.end(), Account);
I need each struct of my vector to be to be organized, say for instance, in descending/ascending order the position number that each contains.
I just need help on (1) bool operator function (e.g. parameters and return values), and (2) How do I have it so that I can sort it by multiple variables like the positions, scores & level. (Would I need to have 3 bool operator functions?)
First of all, your operator is incorrect: it should be either non-member function taking 2 arguments or member function takin one argument.
Second, it looks like it is intended to compare Account elements, but take User ones.
Third, you are declaring two variables with same name in it.
(2) What do you exactly want? To sort simultaneously (first by name and if names are same sort by position) or three different types of sorting?
Well, I have posted a link to example. You need a "predicate" example (both sort call and predicate definition.)
Just define 3 of them comparing different fields.