标题:[求助]stl sort中的谓词参数
取消只看楼主
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
 问题点数:0 回复次数:1 
[求助]stl sort中的谓词参数

sort中第三个参数是个函数指针,返回类型bool,接受两个元素对象。

我想知道其完整的定义类型

bool (*pred) (****,****);

搜索更多相关主题的帖子: stl sort 谓词 参数 
2007-10-14 12:34
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
得分:0 

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


Fight  to win  or  die...
2007-10-14 15:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-177497-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.224104 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved