function as agument ?

i need for one of my projects
to pass a function into a function
example :
double differencial( double x , double dx , ??? func )
{
return ( func( x + dx ) - func( x ) ) / dx ;
}
what do i do whit ??? ?
and in my fuction ?
Look at either std::function (from TR1 in <functional>) or the Boost Function library. It makes this sort of thing fairly trivial.

Or you can use function pointer syntax: http://www.newty.de/fpt/fpt.html
The way to declare variables which are pointers to functions is a little weird in C. Here is an example:

1
2
3
double div3( int a ) { return a / 3.0; }

double (*func)( int ) = div3;


func is the name of the variable. It's type is double (*)( int ), or, in other words,
a pointer to a function which returns a double and takes an int as parameter.

You can now call the function this way:

 
double answer = (*func)( 10 );


And this will call div3() with 10 as parameter and store the result in answer.

Topic archived. No new replies allowed.