gpt4 book ai didi

c++ - xutility.h 错误 C2064 : term does not evaluate to a function taking 2 arguments

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:46:53 28 4
gpt4 key购买 nike

我有问题要问。

我创建了一个名为 AstarPlanlama 的类并具有以下 2 个函数:

bool AstarPlanlama::nodeComp(const Node* lhs, const Node* rhs) 
{
return lhs->F < rhs->F;
}

void AstarPlanlama::enKucukFliNodeBul(std::list<Node*> * OPEN)
{
std::list<Node*>::iterator it = std::min_element(OPEN->begin(), OPEN->end(), &AstarPlanlama::nodeComp);

OPEN->sort(&AstarPlanlama::nodeComp);

Q = OPEN->front();

OPEN->pop_front();
}

当我编译我的代码时,错误发生在 xutility.h 文件中。

template<class _Pr, class _Ty1, class _Ty2> inline
bool _Debug_lt_pred(_Pr _Pred,
_Ty1& _Left, _Ty2& _Right,
_Dbfile_t _File, _Dbline_t _Line)
{ // test if _Pred(_Left, _Right) and _Pred is strict weak ordering
if (!_Pred(_Left, _Right))
return (false);
else if (_Pred(_Right, _Left))
_DEBUG_ERROR2("invalid operator<", _File, _Line);
return (true);
}

函数的声明:

    bool nodeComp(const Node* lhs, const Node* rhs);

void enKucukFliNodeBul(std::list<Node*> * OPEN);

错误行是if (!_Pred(_Left, _Right))

代码有什么问题?

感谢您的返回..

我的问候..

最佳答案

看起来您正在传递一个成员函数作为您的自定义比较器。使其成为 static 或使用 std::bind:

 std::list<Node*>::iterator it = std::min_element(OPEN->begin(), OPEN->end(),
std::bind(&AstarPlanlama::nodeComp,
this,
std::placeholders::_1,
std::placeholders::_2));

OPEN->sort(std::bind(&AstarPlanlama::nodeComp,
this,
std::placeholders::_1,
std::placeholders::_2));

成员函数比较特殊,需要在对象上调用,这就是为什么需要std::bind绑定(bind)到this指针的原因。

关于c++ - xutility.h 错误 C2064 : term does not evaluate to a function taking 2 arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13922992/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com