Here are three functions, such as: -
float Plus (float a, float b) { return a+b; } float Minus (float a, float b) { return ab; } float Multiply(float a, float b) { return a*b; }
now there is a function that takes a pointer to a function as one of the arguments: -
void Function_Pointer_func(float a, float b, float (*pt2Func)(float, float)) { float result = pt2Func(a, b);
and to call the above function "Function_Pointer_func" the function is written below
void Replace() { Function_Pointer_func(2, 5, /* pointer to function 'Minus' */ Plus);//// (1) Function_Pointer_func(2, 5, /* pointer to function 'Minus' */ &Minus);//// (2) }
Why the function above works fine, since the Function_Pointer_func function takes a function argument as an argument. And if we replace RHS in line
float result = pt2Func(a, b); // call using function pointer
function "Function_Pointer_func" (* pt2Func) (a, b), and then it works, but for (& pt2Func) (a, b);
it gives an error in VS2008:
"C2064: the term does not evaluate a function that takes 2 arguments"
Now replace the argument "float (* pt2Func) (float, float)" in the function "Function_Pointer_func" with float (pt2Func) (float, float), and then all three
float result = pt2Func(a, b);
The task
works why? Hopefully the reason for my discomfort is understanding the basic understanding of a pointer function. Well, I can not imagine Q? without any good reading, but yes, I have not done any intensive research on this subject, so please feel free to recommend some readings in this regard that would clear up my ambiguity.
Thanks for the help in advance.