Click here to Skip to main content
15,889,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Math.h
class Math
{
    public:
    static double integrate(double (*f)(double x), double a, double b);
};


Math.cpp
#include "Math.h"

double Math::integrate(double (*f)(double x), double a, double b)
{
    int m = 1000;
    double dt = (b-a)/m;
    double c = 0;

    for(int i = 0; i<m;>    {
        c += (*f)(a+i*dt);
    }

    return c/m;
}


Model.cpp
...
double Model::i_L_charging(double t)
{
    return V_in/(R_L+RDSON) - V_in/(R_L+RDSON)*exp(-t/tau_charging());
}

double Model::I_d_avg()
{
    return math.integrate(&i_L_charging, 0.0, T_charging()); //Error is here
}
...


The shortend error is (GNU GCC Compiler):

||In member function `double Model::I_d_avg()':|

|45|error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say `&Model::i_L_charging'|

|45|error: no matching function for call to `Math::integrate(double (Model::*)(double), double, double)'|

|5|note: candidates are: static double Math::integrate(double (*)(double), double, double)|

||=== Build finished: 2 errors, 0 warnings ===|


Just as a test I put "sqrt" in as the function instead of "i_L_charging" and it works perfectly. What is going on here?

Your help is appreciated.

Regards,
Johnny
Posted
Updated 1-Nov-10 2:38am
v2

1 solution

See http://www.parashift.com/c++-faq-lite/pointers-to-members.html[^]

That should tell you what you need to change to get that working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900