Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass into the function pointer to function?

Tags:

c++

Is it possible to create a function which takes a pointer to another function? How does the prototype of such a function look like?

like image 438
D_E Avatar asked Jan 17 '23 01:01

D_E


1 Answers

typedef int (*func)(float, char);

int something_that_takes_a_func(func f) { return f(3.14, 3); }

int foo(float a, char b) { return a - b; }

std::cout << something_that_takes_a_func(&foo) << "\n";
like image 56
Oliver Charlesworth Avatar answered Jan 29 '23 17:01

Oliver Charlesworth