function passed as parameter.... 
Author Message
 function passed as parameter....

Hello,

I don't know how to define a function that takes a function as parameter ?

Example :

(a and b are of type1)

b=a.function1 (function 2)

where the definition of function 2 is :

type2 function2 (type3)

Thanks



Thu, 16 Aug 2001 03:00:00 GMT  
 function passed as parameter....
Here is some example code:

#include <stdio.h>

typedef double (*FUNCT)(double,double);

double mult(double x, double y)
{
 return x * y;

Quote:
}

double div(double x, double y)
{
 return x / y;

Quote:
}

double add(double x, double y)
{
 return x + y;

Quote:
}

double sub(double x, double y)
{
 return x - y;

Quote:
}

double chooseFunct(FUNCT f,double x,double y)
{
 return f(x,y);

Quote:
}

int main()
{
 double x = 80.0;
 double y = 81.0;

 printf("x * y = %5.2f\n",chooseFunct(mult,x,y));
 printf("x / y = %5.16f\n",chooseFunct(div,x,y));
 printf("x + y = %5.2f\n",chooseFunct(add,x,y));
 printf("x - y = %5.2f\n",chooseFunct(sub,x,y));

 return 0;

Quote:
}

--

Paul Lutus
www.arachnoid.com

Quote:

>Hello,

>I don't know how to define a function that takes a function as parameter ?

>Example :

>(a and b are of type1)

>b=a.function1 (function 2)

>where the definition of function 2 is :

>type2 function2 (type3)

>Thanks



Thu, 16 Aug 2001 03:00:00 GMT  
 function passed as parameter....
Thanks a lot

I like the quotes on your homepage....

b



Thu, 16 Aug 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Calling a member function passed as parameter

2. Passing C++ Class Member Function to as a C Callback Function Parameter

3. calling C++ function from Fortran: parameter passing

4. how do I pass arrays as parameters to functions - newbie

5. parameters pass between function and main

6. Passing parameters to a Thread'ed function

7. Pass parameter to a function

8. Pb with passing a function as parameter

9. Passing parameters to a function

10. passing parameters with functions

11. passing unknown number of parameters to a function

12. optional parameter passing in Turbo C functions

 

 
Powered by phpBB® Forum Software