Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing functions as parameters 1

Status
Not open for further replies.

mrhegemon

Programmer
Jul 3, 2003
20
0
0
US
I would like to be able to pass a particular function to another function so that I may call that specific function from within the function it was passed to, i.e.:

[tt]double func2(int a,long b,double c);
double *func1(long a,long b,*func2(...))
{
...;
func2(...);
..;
}[/tt]

How does one go about this?

I am trying to make a function that calculates the chi-squared gradient and hessian matrix for the coefficients of some non-linear function. I would like to be able to pass the non-linear function to the function that finds these matrices.
 
I believe it's like this...
Code:
double func2(int a,long b,double c);

double *func1(long a,long b,*func2(...))
{
  double  rv;
  ...;
  rv = (* func2)(...);
  ..;
}
Or something like that.

Hope this helps.

 
Like so
Code:
double func2(int a,long b,double c);
double *func1(long a,long b, double (*fn)(int,long,double) )
{
  ...;
  fn(a,b,c);
  ..;
}

Which you would call like so
Code:
double *result = func1( a, b, func2 );
 
Thank you, Salem, that was exactly what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top