如何解决错误:"当在类中使用std :: bind时,没有用于调用'bind(<unresolved overloaded function type>"的匹配函数)

Hec*_*Lee 2 c++ stl

通常,std :: bind在boost :: math :: tools :: bisect()中运行良好.但是,当我尝试在具有成员函数的类中使用std :: bind时,始终存在错误:"没有用于调用'bind('的匹配函数)

这是该类的一个成员函数:

    double SingleCapillaryTube::calLocationFunctionWithoutAngle(const TubeGeometry &TG,
                                const FluidProperties &FP, double tempLocation,
                                double initialLocationValue, double tempTime,
                                const double initialTimePoint)
{
    auto coefficientB = calCoefficientB(TG, FP);
    auto coefficientA = calCoefficientA(TG, FP);
    auto coefficientD = calCoefficientD(TG, FP);
    auto tempValue = -coefficientB * (tempLocation - initialLocationValue) - \
                    1./2. * coefficientA * (pow(tempLocation, 2.) - \
                    pow(initialLocationValue, 2.)) - coefficientD * \
                    (tempTime - initialTimePoint);
    return tempValue;
}
Run Code Online (Sandbox Code Playgroud)

然后此函数用于该类的其他成员函数:

void SingleCapillaryTube::calLocationInterfaceBisect()
{
stepResult = boost::math::tools::bisect(std::bind(calLocationFunctionWithAngle,\
                                            Geometry, Fluids, _3, initialLocation, \
                                            timePoint, initialTime), 0.0, \
                                            -Geometry.length, Tol);
}
Run Code Online (Sandbox Code Playgroud)

编译文件时,始终会发生错误.有人可以帮我解决这个问题吗?非常感谢:)

Mil*_*nek 5

非静态成员函数需要调用实例.为此,将this指针作为函数的第一个参数传递.您还需要使用函数的完整限定名称并获取其地址:

std::bind(&SingleCapillaryTube::calLocationFunctionWithAngle, this,
          Geometry, Fluids, _3, initialLocation, timePoint, initialTime)
Run Code Online (Sandbox Code Playgroud)

另请注意,using _3将第三个位置参数绑定到该参数,因此在这种情况下,将忽略第一个和第二个参数.你可能想要_1那个地方.