Revist
Revist

Reputation: 345

Term does not evaluate to a function taking three arguments

I try to use boost::numerics::odeint to integrate a system of differential equations. My code is

dMat Equation::solveODE(dMat u_i, double t_i)
{

dVec u_iVec(2 * u_i.size());
u_iVec = MtoV(u_i);

void(Equation::*pointer)(const dVec &, dVec &, const double ) = &Equation::ODEf;

runge_kutta4< dVec > stepper;
integrate_const(stepper, pointer, u_iVec, 0.0, 1.0, 0.01);

return u_i;
}

void Equation::ODEf(const dVec &u_i, dVec &dxdt, const double /* t */)
{
    for (size_t I = 0; I < u_i.size(); I++)
{
    if (I % 2 == 0)
    {
        dxdt[I] = f1(VtoM(u_i, u_i.size() / 2, 2))[I];
    }
    else
    {
        dxdt[I] = f2(VtoM(u_i, u_i.size() / 2, 2))[I];
    }

}
}

MtoV only changes a matrix to a vector, f1 and f2 evaluate the rhs of the equation. I had thought that the problem is that ODEf is a member function od Equation (I was getting the error that I have non-standard syntax) but now I get the error that the term does not evaluate to a function taking 3 arguments... Is it maybe because ODEf is member function of Equation once again?

ANSWER: I had to use: std::function ODEf_without_classname(std::bind(&Equation::ODEf, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

in order to get rid of the Equation:: at the beginning of Odef.

Upvotes: 0

Views: 706

Answers (1)

erenon
erenon

Reputation: 19118

pointer is not a function taking 3 arguments, it is a member function pointer; slightly different, conceptually also takes a 0th argument, the this pointer. Try to use a free function/a function object/a bind expression or a lambda.

Upvotes: 1

Related Questions