在MFC中使用sort函数做排序时遇到一个小bug 记录一下

在MFC中使用sort函数做排序时遇到一个小bug 记录一下

在MFC中使用sort函数出错

class CClientSocket :
public CSocket
{
public:
CClientSocket(void);
~CClientSocket(void);

virtual void OnReceive(int nErrorCode);		//重写接收函数,通过类向导生成

BOOL SendMSG(LPSTR lpBuff,int nlen);		//发送函数,用于发送数据给服务器

BOOL highPricerank(const StockRank &a,const StockRank &b);

BOOL closePricerank(const StockRank &a,const StockRank &b);

BOOL lowPricerank(const StockRank &a,const StockRank &b);

BOOL openPricerank(const StockRank &a,const StockRank &b);

};

在该头文件中做了声明,相应的cpp文件中实现函数。编译时报错,stable_sort(last,last+50,&CClientSocket::highPricerank)出了错误。

提示错误代码为:error C2064: 项不会计算为接受 2 个参数的函数。

错误原因:操作func函数要是全局函数或者类的静态函数,不能定义为类的静态函数。

在相应cpp文件外部定义需要的func函数为全局函数,将类中的成员函数注释掉。

using namespace std;

CClientSocket::CClientSocket(void)
{
}

CClientSocket::~CClientSocket(void)
{
}

BOOL openPricerank(const StockRank &a,const StockRank &b)
{
return a.openPriceRank<b.openPriceRank;
}

在后面使用stable_sort函数,stable_sort(now,now+50,openPricerank);即可,编译通过

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值