c++中对于list 模板中的sort的引用 怎么就错了人-> i.sort(sortp);
#include<iostream>#include<list>
using namespace std;
bool sortp(const int& l,const int& k)
{
//define criteria for list::sort :return ture for desired oder
return (l>k);
}
template<typename T>
void display(const T& input)
{
for(T::const_iterator jj=input.begin();jj!=input.end();jj++)
{
cout<<*jj;
}
cout<<endl;
}
int main()
{
list<int> i;
i.push_front(3);
i.push_front(3);
i.push_front(9);
i.push_front(1);
i.push_front(0);
i.push_back(5);
cout<<" the fist list :";
display(i);
i.sort();
cout<<"after sort:"<<endl;
display(i);
i.sort(sortp);
cout<<" oder new:"<<endl;
display(i);
return 0;
}
error C2664: 'void __thiscall std::list<int,class std::allocator<int> >::sort(struct std::greater<int>)' : cannot convert parameter 1 from 'bool (const int &,const int &)' to 'struct std::great
er<int>'
No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.