How to declare and use typedef for a function pointer in C++?
Hello everyone! I'm a beginner C++ developer, and I'm confused about the syntax for declaring function pointers. I'm trying to write a simple calculator that calls the appropriate arithmetic operation based on user choice. Instead of writing a long switch-case, I want to use an array of function pointers.
I've seen that you can declare a function pointer directly, but it looks very cumbersome. For example, for the function `int add(int a, int b)` I would write `int (*funcPtr)(int, int) = add`. And if I have 4 functions (add, subtract, multiply, divide), then I need 4 such declarations.
I've heard somewhere about `typedef` to simplify this task. I tried to write:
```cpp
typedef int (*Operation)(int, int);
```
But the compiler complains or I don't understand how to use it correctly.