C++ STL list::sort(Compare Comp) compile error: "no matching member function for call to 'sort' ... where compare function has been templatized.

Question is related to C++ STL list::sort(Compare) where Compare is now a template.

I am looking for the correct syntax to override the list::sort(Compare) definition to work with list<pair<int, T> > definition.

//-The Compare Function

template<typename W>
bool weightsort(const pair<int, W> &node1, const pair<int, W> &node2)
    return (node1.second <= node2.second);

//- Abbreviated class definition containing  STL list definition and call to sort

template<typename T>
class Graph {
    vector<T> shortest_reach(int startId, T sigWeight) {
        list<pair<int, T> >                                       frontier;   //-Nodes currently on the Queue to be Explored.
        typename list<pair<int, T> >::iterator      fit;

$ c++ program.cpp

error: no matching member function for call to 'sort'

usr/include/c++/v1/list:1059:14: note: candidate template ignored:
      couldn't infer template argument '_Comp'
        void sort(_Comp __comp);
/usr/include/c++/v1/list:1056:10: note: candidate function not viable:
      requires 0 arguments, but 1 was provided
    void sort();
J FAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertFabrice LambertCommented:

start by remove this horrible "using namespace std;" that you're hiding, and fully qualify your data types. I suspect some ambiguities.
You're full class definition and dependencies will probably help also.
J FAuthor Commented:
I did as you suggested and I still have the same compiler errors.
bool weightsort()  worked prior to converting it to a template.
J FAuthor Commented:
The call to frontier.sort(weightsort) was missing the template parameter.
The solution is to call  frontier.sort(weightsort<T>) .

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.