Returns an example pointer to a function in C++

  • 2020-04-02 01:31:11
  • OfStack

In C++, the parameter of a function can be a pointer to a function or a function can return a pointer to a function.
Such as:
Int (* ff (int)) (int x, int); Ff (int) is a function with an int parameter. The function returns an int (*) (int *,int).
Using a typedef makes the definition more understandable:
Typedeff int (*PF) (int *,int);
PF ff (int);
Here's an example:

using namespace std;
void fff(int *i,int j)
void (*f(int))(int* pi,int i)
  return fff;
typedef void (*((*pf)(int)))(int*,int);
int main()
  pf p;
  int i;
  int *ip;
  return 0;

Output results:

Related articles: