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: problems using gsl routines in C++ objects


On Wed, 27 Feb 2002, Daniel Rohe wrote:

I suppose that the following combines both ideas:

#include <iostream>

double apply( double (*func)(double , void *), double x, void* y )
{
  return func(x,y);
}

class X
{
public:
  X(double aa) : a(aa) {};
  static double f( double b, void* obj )
  {
    X* x = (X*) obj;
    return b * x->a ;
  }
private:
  double a;
};

int main()
{
  X x(4);
  cout << apply( X::f, 2, (void*)&x ) << endl;
  return 1;
}


> ok, this is a possible solution. however I'm a little concerned about
> the performance loss.
> the integration over this function will be one of the low lying
> routines, therefore an extra indirection
> could lead to a substantial loss in performance.
>
> the workaround I was thinking of consists of defining a "classless"
> static function and passing
> all relevant object attributes via the parameters-interface. this
> however destroys in a way the C++
> idea of "encapsulated data", but I guess at this point one has to make
> certain compromises.
>
> anyway I'll try both solutions and see what happens.
>
> thanks for the help!!
>
> daniel



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