matching function for call to"/>
error: no matching function for call to
原文地址:error:今天用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)
{
}
错误的原因是比较函数PhasePairLess应当是static的。将头文件中的函数声明改为:
static boolPhasePairLess(pair<int,double>p1,pair<int,double> p2);
编译通过。注意,cpp文件中不用static。
更多推荐
error: no matching function for call to
发布评论