help-gsl
[Top][All Lists]
Advanced

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

Re: [Help-gsl] Problems with siman in c++ class


From: Paulo Jabardo
Subject: Re: [Help-gsl] Problems with siman in c++ class
Date: Fri, 16 Feb 2007 19:57:50 -0300 (ART)

Sorry I made a stupid mistake...

    // Function that will be used by gsl_siman_solve
    static double my_fun(void *xp)
    { 
      Efunct_param *par = (Efunc_param*) xp;// STUPID
ERROR
      MyClass *this = par->this;
      // With this you can access instance
 variables/methods
     ...
    }
 

--- Paulo Jabardo <address@hidden> escreveu:

> I've never used these functions but if I understand
> correctly your problem, I think you need to declare
> your member function static. If it is not declared
> static, there is a hidden argument in the method (a
> pointer to the object itself, accessible through
> "this").
> 
> 
> The problem is that you probably want to use
> instance
> variables in your class. To do this you need to pass
> a
> pointer to the object instance that interests you.
> I've never used these functions but grasping from
> the
> documentation I guess you are having trouble with
> the
> gsl_siman_Efunc_t type function. This function has
> an
> argument that is a pointer to void (void *xp).
> 
> If your class is called MyClass, my suggestion is
> for
> you to create a struct like
> 
> struct Efunct_param
> {
>   MyClass *this;
>   // Other parameters needed by the simulation
>   ...
> };
> 
> class MyClass
> {
> ...
>    // Function that will be used by gsl_siman_solve
>    static double my_fun(void *xp)
>    { 
>      Efunct_param *par = (MyClass*) xp;
>      MyClass *this = par->this;
>      // With this you can access instance
> variables/methods
>     ...
>    }
> 
>   void function_that_uses_gsl(void)
>   {
>     Efunc_param pars;
>     pars.this = this;
>     // set other fields of pars
>     gsl_siman_solve(..., my_fun, ...);
>   }
> 
>   ...
> };
> 
> I think this might help.
> 
> Paulo
> 
> 
> 
> --- Ross Williamson <address@hidden>
> escreveu:
> 
> > Dear all
> > 
> > I have a c++ class to control and optimize a piece
> > of equipment here in
> > the lab.  We wish to use simulated annealing
> package
> > from GSL.  We are
> > calling the gsl_siman_solve from inside the class
> > passing functions that
> > are public members of the same class.
> > 
> > The problem is that we can not get the damn thing
> to
> > compile - we cannot
> > simply type the name of the function in instead it
> > wants
> > &classname::function and that doesn't work either.
> > 
> > Has anyone got siman running from inside a c++
> class
> > using functions
> > declaired in the class?
> > 
> > Many thanks
> > 
> > Ross
> > 
> > 
> > 
> > _______________________________________________
> > Help-gsl mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/help-gsl
> > 
> 
> 
> __________________________________________________
> Fale com seus amigos  de graça com o novo Yahoo!
> Messenger 
> http://br.messenger.yahoo.com/ 
> 
> 
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
> 


__________________________________________________
Fale com seus amigos  de graça com o novo Yahoo! Messenger 
http://br.messenger.yahoo.com/ 




reply via email to

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