error: no matching function for call to

今天用c++标准模板库(STL)中的sort算法给一个vector<pair<int,double>>对象排序时遇到了题目中的编译时错误:(问题虽然简单,却让我弄了整整一下午)

error: no matching function for call to'sort(__gnu_cxx::__normal_iterator<std::pair<int,double>*  ......

note: candidates are: void std::sort(_RandomAccessIterator,_RandomAccessIterator, _Compare) ......

 

程序是这样的:

fourdct.h

boolPhasePairLess(pair<int,double>p1,pair<int,double>p2);//这是fourdct类的成员函数。

 

fourdct.cpp

vector<pair<int,double>> phasePairVector;

....

sort(phasePairVector.begin(),phasePairVector.end(),PhasePairLess);

 

boolFourDCT::PhasePairLess(pair<int,double>p1,pair<int,double> p2)
{
 return p1.second <p2.second;
}

错误的原因是比较函数PhasePairLess应当是static的。将头文件中的函数声明改为:

static boolPhasePairLess(pair<int,double>p1,pair<int,double> p2);

编译通过。注意,cpp文件中不用static。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值