C++ Function Pointers
Introduce 4 ways to define function pointers in C++.
- Traditional
- typedef
- using
- std::function
1. Traditional
Syntax
| 1 | return_type (*pointer_name)(parameter_types1, parameter_types2); | 
2. typedef
Syntax
| 1 | typedef return_type (*pointer_name)(parameter_types1, parameter_types2); | 
funcPtr becomes an alias for the type “pointer to a function that takes two int parameters and returns an int”.
3. using
Syntax
| 1 | using pointer_name = return_type (*)(parameter_types1, parameter_types2); | 
funcPtr becomes an alias for the type “pointer to a function that takes two int parameters and returns an int”.
4. std::function
Syntax
| 1 | std::function<return_type(parameter_types1, parameter_types2)> pointer_name; | 
5. Example
| 1 | 
 | 
C++ Function Pointers
