error: no matching function for call to

编程入门 行业动态 更新时间:2024-10-07 06:39:29

error: no <a href=https://www.elefans.com/category/jswz/34/1762998.html style=matching function for call to"/>

error: no matching function for call to

原文地址:error: no matching function for call to 作者:brightmoon

今天用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。

更多推荐

error: no matching function for call to

本文发布于:2024-02-14 11:39:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1763339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:matching   error   call   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!