[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [Help-gsl] gsl_function in c++

**From**: |
Martin Jansche |

**Subject**: |
Re: [Help-gsl] gsl_function in c++ |

**Date**: |
Mon, 24 Jul 2006 09:56:26 -0400 |

On 7/24/06, Ivan Liu <address@hidden> wrote:

Thanks Martin. But could you make it more explicit? How do you use
"this" pointer to pass the constant parameters?

Suppose you want to find a root of a quadratic function f with
parameters b and c, defined as follows:
f(x) = x^2 + b*x + c
(Just for the sake of illustration; of couse you could find the roots
analytically in this particular case.) Then you could implement this
as follows (Java syntax):
class QuadraticFunction
implements Function // (as in a previous message)
{
double b;
double c;
QuadraticFunction(double b, double c) {
this.b = b;
this.c = c;
}
public double f(double x) {
return (x + this.b) * x + this.c;
}
}
GSL gives you essentially the same design, except that it happens to
be written in C, so there is no implicit "this" pointer, and instead
an explicit void pointer for handling arbitrary fixed parameters has
to be passed around. C++ simply hides that part from you.
-- mj