gpt4 book ai didi

c++11 - std::bind 没有可行的转换

转载 作者:行者123 更新时间:2023-12-01 07:37:55 25 4
gpt4 key购买 nike

我创建了一个寻路算法,我可以在其中设置启发式方法。
但我正在使用

function<int (Point2i origin, Point2i destiny)> heuristicFunc;

作为我的函数指针,我想用我的默认 Heristic 初始化它。

所以:

寻路程序.h
class Pathfind{
private:
function<int (Point2i origin, Point2i destiny)> heuristicFunc;
int hMethod(Point2i origin, Point2i destiny);
public:
Pathfind();
}

寻路.cpp
Pathfind::Pathfind(){
//1st try
this->heuristicFunc=&Pathfind::hMethod;
//2nd try
this->heuristicFunc=std::bind(&Pathfind::hMethod, this);
}

但它返回相同的错误:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/functional:1472:15:候选函数不可行:没有来自'int的已知转换(Core::Pathfind::* )(Point2i, Point2i)' 到 'const std::__1::function, sf::Point2)>' 第一个参数

为什么它试图从 int(Core::Pathfind::*) 转换?

谢谢。

最佳答案

using namespace std::placeholders;
heuristicFunc = std::bind(&Pathfind::hMethod, this, _1, _2);

您未提供的每个参数都必须通过占位符指示。

关于c++11 - std::bind 没有可行的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26350921/

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