I have a function, that declared next way:
func(int n,double *xk, double (*f)(int x));
I want to assign that into one word like typedef int (*func_t)(int, *double, ...);
. I know how to assign function, but do not understand how to describe function in arguments.
You can do
typedef double (*FuncPtr)(int x);
int func(int n,double *xk, FuncPtr f);
typedef int (*func_t)(int,double*,FuncPtr);
One step at a time to reduce unnecessary confusion and clutter.
typedef int (*func)(int, double*, double (*)(int));
assuming that the function declaration looks like:
int func(int n, double *xk, double (*f)(int x)) {
// ...
}
then the typedef of a pointer to this function would look like:
typedef int (*funcPointer)(int, double *, int, int, double (*)(int));
// usage:
funcPointer ptrName = func;
assuming you want to give this ptrName to a function called doThis():
int doThis (funcPointer ptrName) {
return 0;
}
then you can just call it using:
int y = doThis(ptrName);
Best of luck ! =)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.