简体   繁体   中英

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

Usually, std::bind works well in boost::math::tools::bisect(). However, when I tried to use std::bind in a class with member functions, there is always error: " no matching function for call to 'bind( "

This is one member function of the class:

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

Then this function is used in the other member function of the class:

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

When the file was compiled, the error always occurred. Could someone help me solve this problem? Thanks very much:)

Non-static member functions need an instance to be called on. To give it that, pass your this pointer as the first argument to the function. You also need to use the full qualified name of the function and take its address:

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

Also note that using _3 binds the third positional argument to that parameter, so in this case the first and second arguments will be ignored. You likely want _1 in that spot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM