can't complie and run..

//Exercise P11.10, sort a vector of Employee objects by salary using the standard C++ sort function.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "ccc_empl.h"
using namespace std;


bool operator<(const Employee& a, const Employee&b)
{
return a.get_salary() < b.get_salary();
}

int main()
{
vector<Employee> list;
list.push_back(Employee ("Sean Lee", 40000));
list.push_back(Employee ("Kevin Lee", 30000));
list.push_back(Employee ("Chee Yang", 50000));

sort( list.begin(), list.end() );


for (unsigned int i = 0; i < list.size(); i++){
cout << "Employee name: " << list[i].get_name() << "\n";
cout << "Salary: " << list[i].get_salary() << "\n";
}

return 0;
}
And the problem is...?
The problem could be the combination of

 
using namespace std;


with naming the variable "list", but it's hard to say...
I hope this helps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Employee
{
  public:
	Employee(string name, int salary) {
		Employee::name = name;
		Employee::salary = salary;
	}

	string get_name() const {
		return Employee::name;
	}

	int get_salary() const {
		return Employee::salary;
	}

	bool operator< (const Employee& b) const {
		return Employee::get_salary() < b.get_salary();
	}

  private:
	int salary;
	string name;
};



int main()
{
    vector<Employee> my_vector;

    my_vector.push_back(Employee ("Sean Lee", 40000));
    my_vector.push_back(Employee ("Kevin Lee", 30000));
    my_vector.push_back(Employee ("Chee Yang", 50000));


    sort( my_vector.begin(), my_vector.end() );


    for (int i = 0; i < my_vector.size(); i++)
    {
        cout << "Employee name: " << my_vector[i].get_name() << "\n";
        cout << "Salary: " << my_vector[i].get_salary() << "\n\n";
    }
    return 0;
}
Topic archived. No new replies allowed.