[comp.lang.c++] Numerical Methods and C++

dsamperi@Citicorp.COM (Dominick Samperi) (09/10/90)

I'd like to open the following topic for discussion. Assume that
you have an efficient numerical method; for definiteness, let's
say the method solves for the largest root of the equation
f(x) = 0. Assume that the C++ interface to this function looks like:

double BigRoot(double (*f)(double)) ;

Now, assume that a large number of objects from various classes
have associated functions (member functions or friends) like f()
for which we would like to implement a solver like BigRoot(). But
the object functions are of the form F(x, y, z, w, ...) where all
parameters except x are held fixed when BigRoot() is used.

The problem is: what is the best (cleanest/type-safe) way to provide
a BigRoot() for a generic object that has an associated
F(x, y, z, ...), WITHOUT reimplementing the root-finding algorithm for
each class. The simplest solution is to define an auxiliary function
f(x) that simply calls F(x, y, z, ...), but this requires that the
parameters y, z, etc. be saved somewhere (these parameters could also
be attributes of the class --- then the object of the class must be saved
somewhere, and the definition in this case looks like f(x) = F(x, OBJ)).
I'm looking for a cleaner solution than this.

Thanks in advance.

-- 
Dominick Samperi -- Citicorp
dsamperi@Citicorp.COM
uunet!ccorp!dsamperi