std :: bind没有可行的转换

Lef*_*ler 3 functor c++11

我创建了一个pathfind算法,我可以设置启发式方法.但我正在使用

function<int (Point2i origin, Point2i destiny)> heuristicFunc;
Run Code Online (Sandbox Code Playgroud)

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

所以:

Pathfind.h

class Pathfind{
    private:
        function<int (Point2i origin, Point2i destiny)> heuristicFunc;
        int hMethod(Point2i origin, Point2i destiny);
    public:
      Pathfind();
}
Run Code Online (Sandbox Code Playgroud)

Pathfind.cpp

Pathfind::Pathfind(){
    //1st try
    this->heuristicFunc=&Pathfind::hMethod;
    //2nd try
    this->heuristicFunc=std::bind(&Pathfind::hMethod, this);
}
Run Code Online (Sandbox Code Playgroud)

但它返回相同的错误:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/functional:1472:15:候选功能并不可行:没有已知的转换,从"诠释(核心:: Pathfind ::*)(Point2i,Point2i)'到'const std :: __ 1 :: function,sf :: Point2)>'为第一个参数

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

谢谢.

Col*_*mbo 11

using namespace std::placeholders;
heuristicFunc = std::bind(&Pathfind::hMethod, this, _1, _2);
Run Code Online (Sandbox Code Playgroud)

您不提供的每个参数都必须通过占位符表示.