<unresolved overloaded funciton type>中文意思是:<未解析的重载函数类型>
我放一部分我的报错代码:
bool cmp(const Edge<TV, TE> &a, const Edge<TV, TE> &b) {
return(a.weight < b.weight);
}
std::sort(edgeArr, edgeArr + edgeNum, cmp);
而且,上面那些都是在一个类里(注意:这里是报错的重点)
template<class TV, class TE> class AdjListGraph {...}
编译后就会有这样的报错:
[Error] no matching function for call to 'sort(Edge<int, int>*&,
Edge<int, int>*, <unresolved overloaded function type>)'
void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter =
Edge<int, int>*; _Compare = bool (AdjListGraph<int, int>::*)
(const Edge<int, int>&, const Edge<int, int>&)]
no known conversion for argument 3 from
'<unresolved overloaded function ty

在C++编程中遇到<unresolved overloaded function type>错误,原因是cmp函数非静态导致。报错代码显示std::sort找不到匹配的cmp函数。解决方法是将cmp方法声明为static,因为非静态方法会隐含一个this指针,而sort不会传递这个额外参数。通过将cmp函数改为static类型,问题得到解决。尽管网上的其他方法可能在某些情况下有效,但在作者的程序中,只有将cmp设为static才能避免报错。
最低0.47元/天 解锁文章
748

被折叠的 条评论
为什么被折叠?



