[求助]stl sort中的谓词参数
sort中第三个参数是个函数指针,返回类型bool,接受两个元素对象。
我想知道其完整的定义类型
bool (*pred) (****,****);
oh,I made a unclear expression.
my problem is:
template<class T>
struct X{
typedef bool (*pred)(const T&,const T&); //define a function pointer type
pred p; //pred data member
X(pred _p):p(_p){}
};
bool cmp1(int a,int b){return a<b;}
bool cmp2(const int &a,const int &b){return a<b;}
X<int> x1(cmp1); //doesn't work,compile error
X<int> x2(cmp2); //ok
how I define the type of pred can accept both cmp1 and cmp2?
or maybe I should use the sort(1,2,pred)'s way to implement,because both sort(..,..,cmp1) and sort(..,..,cmp2)
can be accepted,but I don't konw the sort's implementation clearly.
[此贴子已经被作者于2007-10-14 15:19:17编辑过]