G
giulianodammando
Hi to everybody here at the newsgroup. I've a class:
class CrossSection {
public:
// ctor(), dtor()
double getValue(double E);
double integrate(double a, double b); // <-- i'd like to
implement this
private:
// private data members used by getValue()
};
what i need is to numerically integrate the cross section (whose value
is returned by the function
getValue) with respect to the energy. This should be accomplished by a
member function integrate()
(see the prototype in the class declaration) that in turn should rely
on a set of C routines (various integration algorithms) of the form:
typedef double (*f_ptr)(double )
int integrate_gauss (f_ptr, double a, double b, double *result, double
*erel)
int integrate_gauss_legendre (f_ptr, double a, double b, double
*result, double *erel)
int integrate_adapt_step (f_ptr, double a, double b, double *result,
double *erel, size_t maxiter)
etc..
i've tried something like:
double integrate(double a, double b) {
double erel = 1e-8;
double result;
integrate_gauss(&getValue, a,b,&result,&erel);
return result;
}
that obviously does not compile because integrate_xyz functions expect
a
"normal" poiter to a global function and not a pointer to a class
member func.
Sad but true.
Obviously i'd like to use a member integrate() function in order to
access to private
data of the class. in fact I've an array (better, a 2D matrix) of
CrossSection objects, each one with different values of internal
parameters. So the use of static class member functions is not
possible, at the moment, because it should be of the form:
static double staticGetValue(CrossSection *, double E)
wich obviously doesn't fit with the prototype needed by *integrate_xyz*
funcs. Anyway I probably need to use the same integration routines in
other parts of the code, i.e. with other classes.
I think this should be a well known issue in interfacing C code with
C++, but i haven't been able to find a decent solution by myself. I ask
to the more expert (i'm not very confident with c++ at the moment, but
I think that a solution must exist, eventually adding one more level of
deference somewere, that shoul be acceptable for now) people here in
the newsgroup, hoping in the meantime
in an illumination. anyway thanks a lot for reading this message, i
hope i've explained clearly the point. bye
giuliano.
class CrossSection {
public:
// ctor(), dtor()
double getValue(double E);
double integrate(double a, double b); // <-- i'd like to
implement this
private:
// private data members used by getValue()
};
what i need is to numerically integrate the cross section (whose value
is returned by the function
getValue) with respect to the energy. This should be accomplished by a
member function integrate()
(see the prototype in the class declaration) that in turn should rely
on a set of C routines (various integration algorithms) of the form:
typedef double (*f_ptr)(double )
int integrate_gauss (f_ptr, double a, double b, double *result, double
*erel)
int integrate_gauss_legendre (f_ptr, double a, double b, double
*result, double *erel)
int integrate_adapt_step (f_ptr, double a, double b, double *result,
double *erel, size_t maxiter)
etc..
i've tried something like:
double integrate(double a, double b) {
double erel = 1e-8;
double result;
integrate_gauss(&getValue, a,b,&result,&erel);
return result;
}
that obviously does not compile because integrate_xyz functions expect
a
"normal" poiter to a global function and not a pointer to a class
member func.
Sad but true.
Obviously i'd like to use a member integrate() function in order to
access to private
data of the class. in fact I've an array (better, a 2D matrix) of
CrossSection objects, each one with different values of internal
parameters. So the use of static class member functions is not
possible, at the moment, because it should be of the form:
static double staticGetValue(CrossSection *, double E)
wich obviously doesn't fit with the prototype needed by *integrate_xyz*
funcs. Anyway I probably need to use the same integration routines in
other parts of the code, i.e. with other classes.
I think this should be a well known issue in interfacing C code with
C++, but i haven't been able to find a decent solution by myself. I ask
to the more expert (i'm not very confident with c++ at the moment, but
I think that a solution must exist, eventually adding one more level of
deference somewere, that shoul be acceptable for now) people here in
the newsgroup, hoping in the meantime
in an illumination. anyway thanks a lot for reading this message, i
hope i've explained clearly the point. bye
giuliano.