Computer Science Canada Function as a parameter |
Author: | Tubs [ Wed Nov 09, 2005 4:53 pm ] | ||
Post subject: | Function as a parameter | ||
Though I *believe* I have declared all the parameters the correct type and everything else, the program still says that the first argument of eval(); is incorrect (I'm just learning how to input a function as a parameter so it is probably just a syntax problem). Any help or tips would be appreciated as always ![]()
|
Author: | [Gandalf] [ Wed Nov 09, 2005 5:08 pm ] |
Post subject: | |
Well, you don't pass a function to another function, you pass the result of the function. So, if you have something returning a double, and you assign a variable, f, that result, then you would just pass f to the function. Hmm... I was going to give an example, but it seems you don't even have a function eval() in that code ![]() |
Author: | rizzix [ Wed Nov 09, 2005 5:15 pm ] |
Post subject: | |
nay, you can pass functions as parameters.. but he's doing it all wrong.. |
Author: | [Gandalf] [ Wed Nov 09, 2005 5:28 pm ] |
Post subject: | |
Really? Interesting... ![]() Well, I'm pretty sure he just wants to pass the result to the function. Besides, where is this eval()? |
Author: | Tubs [ Wed Nov 09, 2005 5:56 pm ] | ||
Post subject: | |||
sorry.
|
Author: | [Gandalf] [ Wed Nov 09, 2005 6:55 pm ] |
Post subject: | |
The point remains... Quote: Well, you don't pass a function to another function, you pass the result of the function. So, if you have something returning a double, and you assign a variable, f, that result, then you would just pass f to the function. |
Author: | Tubs [ Wed Nov 09, 2005 7:00 pm ] |
Post subject: | |
Yes, that is what I would do when approaching this problem. BUT! Quote: Write a function eval() which takes another function as a parameter and evaluates it over a range of values. The prototype for eval() is:
void eval( double f( double farg ), double start, double step, int count ) Question says otherwise. ![]() |
Author: | Tubs [ Thu Nov 10, 2005 12:12 am ] |
Post subject: | |
no idea? this is boggling me. |
Author: | wtd [ Thu Nov 10, 2005 12:37 am ] | ||
Post subject: | |||
When you declare a pointer to a function, it looks like:
This says you have an argument called "f" which takes a "double" argument, and returns a "double". So when you pass the argument... you just pass the name of the function. |
Author: | Tubs [ Thu Nov 10, 2005 1:20 pm ] |
Post subject: | |
Have i ever told you how i love you wtd |