I am trying to write a template with custom compare function
#include <list>
#include <algorithm>
using std::list;
using std::sort;
template<class T, class Comp=std::less<T>>
class MyList{
public:
list<T> l;
void add(const T& t){
l.push_back(t);
}
void sort(){
sort(l.begin(),l.end(), Comp);
}
};
int main()
{
MyList<int> myList;
myList.add(1);
myList.sort();
return 0;
}
However, I fail to put the compare function as the argument of sort function
main.cpp: In member function ‘void MyList<T, Comp>::sort()’:
main.cpp:26:37: error: expected primary-expression before ‘)’ token
sort(l.begin(),l.end(), Comp);