如何解决错误:"no matching function for call to ‘bind(<unresolved overloaded function type>"在类中使用 std

How to solve the error: "no matching function for call to ‘bind(<unresolved overloaded function type>" when std::bind is used in a class

本文关键字:function unresolved lt type overloaded std gt to 错误 解决 何解决      更新时间:2023-10-16

通常,std::bind在boost::math::tools::bisect()中工作良好。但是,当我尝试在具有成员函数的类中使用std::bind时,总是出现错误:

没有匹配bind(<unresolved overloaded function type>…的函数

这是类的一个成员函数:

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;
}

然后在类的另一个成员函数中使用这个函数:

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

编译文件时,总是发生错误。有人能帮我解决这个问题吗?

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

std::bind(&SingleCapillaryTube::calLocationFunctionWithAngle, this,
          Geometry, Fluids, _3, initialLocation, timePoint, initialTime)

还请注意,使用_3将第三个位置参数绑定到该参数,因此在这种情况下,第一个和第二个参数将被忽略。您可能希望_1在该位置

相关文章: