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());
}
...
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