[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] gsl in c++: pointer to member function
From: |
Carsten Fortmann |
Subject: |
[Help-gsl] gsl in c++: pointer to member function |
Date: |
Sun, 19 Mar 2006 00:47:58 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.7 (X11/20051013) |
How can I pass a pointer to a member function to a
gsl_function struct?
Consider the following excerpt from my code:
#include <math.h>
#include <gsl/gsl_const_mksa.h>
#include <gsl/gsl_roots.h>
#include <gsl/gsl_sf_fermi_dirac.h>
class PLASMA
{
private:
double chempot_Ry(double, double);
double FDhalf(double,void*);
...
...
...
public:
PLASMA();
PLASMA(double n, double t);
~PLASMA();
void Init(double n, double t);
...
...
...
};
...
...
...
double PLASMA::chempot_Ry(double n, double t)
{
const gsl_root_fsolver_type *T;
gsl_root_fsolver *s;
int status;
double root;
double xlo=log(DensE_Ry*pow(TherWavl_Ry,3.)/2.);
double xhi=1./DegePara;
gsl_function F;
//THIS IS THE IMPORTANT PASSAGE
line 202 F.function=&FDhalf;
F.params=NULL;
T=gsl_root_fsolver_bisection;
int maxiter=1000000;
int iter=0;
while(iter<=maxiter)
{
status=gsl_root_fsolver_iterate(s);
root=gsl_root_fsolver_root(s);
xlo=gsl_root_fsolver_x_lower(s);
xhi=gsl_root_fsolver_x_upper(s);
status=gsl_root_test_interval(xlo,xhi,0,0.0001);
if(status==GSL_SUCCESS) return TempE_Ry*root;
else iter++;
}
}
double PLASMA::FDhalf(double x, void *)
{
return gsl_sf_fermi_dirac_half(x)-2./3./pow(DegePara,3./2.);
}
(for those interested: double chempot(double, double) should return the
chemical potential of an electron gas of density
n and temperature t. )
Upon compilation I obtain the following error message:
ISO C++ forbids taking the address of an unqualified or parenthesized
non-static member function to form a pointer to member function. Say
‘&PLASMA::FDhalf’
plasma.h:202: error: cannot convert ‘double (PLASMA::*)(double, void*)’
to ‘double (*)(double, void*)’ in assignment
Don't try to compile this, I deleted everything besides the
relevant parts.
Can anyone help, i.e. tell me how to circumvent this c++-nogo?
carsten
- [Help-gsl] gsl in c++: pointer to member function,
Carsten Fortmann <=