help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] gsl in c++: pointer to member function


From: Lorenzo Moneta
Subject: Re: [Help-gsl] gsl in c++: pointer to member function
Date: Mon, 20 Mar 2006 23:49:25 +0100

Hi,

you can use the void * to pass information about the C++ object to the GSL function,
a possible example is in

http://seal.web.cern.ch/seal/MathLibs/5_0_8/MathMore/html/ GSLFunctionAdapter_8h-source.html

Cheers,

 Lorenzo
On 19 Mar 2006, at 00:47, Carsten Fortmann wrote:

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 mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl





reply via email to

[Prev in Thread] Current Thread [Next in Thread]