help-gsl
[Top][All Lists]
Advanced

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

Re: [Help-gsl] using gsl callback routine from c++ / pointer to member f


From: John D Lamb
Subject: Re: [Help-gsl] using gsl callback routine from c++ / pointer to member function
Date: Wed, 13 Feb 2013 09:20:03 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2

On 13/02/13 08:26, Hershel Safer wrote:
> l define a function myF() to compute f(x), and pass GSL a pointer to myF().
> The problem is that the compiler won't convert from "pointer to myF ()" to
> the way that GSL declares the pointer. This is because C++ treats a
> "pointer to member function" differently from how it treats a pointer to a
> function that is not part of a class. I understand the C++ issue; I hope
> that somebody on this list knows how to get around it.

It can be done. I wrote some C++ wrappers for GSL to avoid ever having
to use alloc or free and to allow member functions in place of
functions: http://sourceforge.net/projects/ccgsl/

This may be a lot more than you need. But the code for
multimin_function.hpp should show you how you can do what you want.
http://www.johndlamb.net/ccgsl/classgsl_1_1multimin_1_1function.html

The code is designed to use member functions with a parameter
gsl::vector& rather than gsl_vector*, but it should be reasonably
straightforward to adapt it.

If you use this kind of approach I’d recommend you use header files for
all the wrappers so that the compiler can optimise away all the details.

-- 
John D Lamb



reply via email to

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