don't know if i understand what you need.
The predicate (I don't know if it should be translated as "weici") can be a funtion pointer and function object --- a class which overloads operator().
Here is what I copied from cplusplus.com
程序代码:
don't know if i understand what you need.
The predicate (I don't know if it should be translated as "weici") can be a funtion pointer and function object --- a class which overloads operator().
Here is what I copied from cplusplus.com
程序代码:

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编辑过]
