This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: C++ wrapping
- From: linas at austin dot ibm dot com
- To: eknecronzontas <eknecronzontas at yahoo dot com>
- Cc: gsl-discuss at sources dot redhat dot com
- Date: Mon, 12 Apr 2004 11:11:30 -0500
- Subject: Re: C++ wrapping
- References: <20040409213614.39240.qmail@web10501.mail.yahoo.com>
On Fri, Apr 09, 2004 at 02:36:14PM -0700, eknecronzontas wrote:
>
> So is there a better way? I'd love to hear any
> ideas.
Sure. Pretend it was c not c++:
class GSLSolver
{
public:
virtual void declare_func_to_solve (double (*f)(double));
virtual double get_solution(void);
private:
double (*fs)(double);
};
void GSLSolver :: declare_func_to_solve (double (*f)(double))
{
fs = f;
}
double my_func (double x) { return x*x-x; }
main () {
GSLSolver mysolver;
mysolver.declare_func_to_solve (my_func);
printf ("the answer is %f\n", mysolver.get_solution());
}
--linas