This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ wrapping


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]