sorting an Array of structs

I saw some similar topics about this, using the sort function, and I tried myself and wasn't able to get it working. Maybe someone could let me know what I'm doing wrong. I have my struct:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct personnel
    {
        string FirstName;
        string LastName;
        int ID;
        string role;
        int duty1;
        int duty2;
        int duty3;
        string duty;
        char exitFlag;
        date admitDate;
        date OptionalExitDate;
        personnel() : FirstName(""), LastName(""), ID(0), role(""), duty1(10), duty2(10), duty3(10), exitFlag('a') {}
    };


I'd like to sort on duty1, so I tried by using this -

bool acompare(personnel lhs, personnel rhs) { return lhs.duty1 < rhs.duty1; }

and then calling it in the main like this -

std::sort(all, all+1000, acompare);

and I keep getting errors within "stl_algo.h" and I can't figure out why.

Thanks!
Last edited on
Could you please post the full error code?
What you have works for C++11, so make sure your compiler is compliant. You can also use a lambda on the following lines:
std:sort(all, all+1000, [] (const personnel& lhs, const personnel& rhs){return lhs.duty1 < rhs.duty1;});
Topic archived. No new replies allowed.