i have problem using the sort algorithm with my list of objects. Here is my code
#include <iostream>
#include <string>
#include <list>
//#include <iterator>
//#include <functional>
#include <algorithm>
using namespace std;
class Project
{
private:
string name;
int days;
public:
Project(string n, int d)
{
name = n;
days = d;
}
int get_days() const
{
return days;
}
void show() const
{
cout << "Name of the project: " << name << endl;
cout << "Days to completion: " << days << endl;
cout << endl;
}
};
static bool sortByAge(const Project &lhs, const Project &rhs)
{
return lhs.get_days() < rhs.get_days();
}
int main()
{
list<Project> l1, l2;
Project ob1("Alpha", 120), ob3("Gama", 60), ob5("Omega", 200);
l1.push_back(ob1);
l1.push_back(ob3);
l1.push_back(ob5);
sort(l1.begin(), l1.end(), sortByAge);
cout << "LIST 1" << endl;
for (const auto& p : l1)
{
p.show();
}
system("pause");
}
And these are the errors
Error 4 error C2676: binary '-' : 'std::_List_iterator<std::_List_val<std::_List_simple_types<Project>>>' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 3157
Error 5 error C2780: 'void std::_Sort(_RanIt,_RanIt,_Diff,_Pr)' : expects 4 arguments - 3 provided c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 3157
Error 3 error C2784: 'unknown-type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<Project>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 3157
Error 2 error C2784: 'unknown-type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<Project>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 3157
Error 1 error C2784: 'unknown-type std::operator -(std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'std::move_iterator<_RanIt> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<Project>>>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\algorithm 3157