Reputation: 23
I am trying to create a function pointer that takes in a pointer to double as an argument. What is the proper syntax to write in main
?
This is what I have but it keeps spitting out errors.
void (*ptr)(double, double, (*double), (*double) );
Upvotes: 2
Views: 89
Reputation: 40305
It is the same way you would declare a double *
parameter in a function's parameter list:
void (* ptr) (double, double, double *, double *);
Can be assigned to a function like:
void something (double w, double x, double *py, double *pz) {
}
This is true in the general case, no matter how complicated it gets. For example, a pointer to a function that takes an int
and another function pointer (which points to a function that takes a double
and a void *
and returns a char*
) as a parameter:
void (* ptr) (int, char * (*) (double, void *));
Then:
char * g (double w, void *) {
...
}
void f (int x, char * (* y) (double, void *)) {
...
}
// usage, elsewhere:
ptr = &f;
ptr(0, &g);
Upvotes: 8