I would also like to ask if there is something wrong (not recommended) with function pointers, since I never see anyone using them.
Yes. Function pointers are terrible, terrible things. Firstly, they do not support generation, so you cannot use a pointer to a function that, for example, takes std::vector<T> for any T Secondly, they do not support a bound state, therefore, if at any time in the future someone wants to refer to another state, they are completely screwed up. This is especially bad since it includes this for member functions.
There are two approaches to performing functions in C ++ 11. The first is to use a template. The second way is to use std :: function.
The template type is as follows:
template<typename T> void func(F f) { f(); }
The main advantages here are that it accepts any function object, including a function pointer, lambda, functor, binding result, anything, and F can have any number of function overloads with any signature, including templates, and can have any size with any bound state. So this is super-duper flexible. It is also as efficient as possible, since the compiler can embed the statement and pass the state directly in the object.
int main() { int x = 5; func([=] { std::cout << x; }); }
The main drawback here is the usual drawbacks of templates - it does not work for virtual functions and should be defined in the header.
Another approach is std::function . std::function has many similar advantages - it can be of any size, attached to any state and be any callable, but it is traded with a pair. Basically, the signature is fixed during the type definition, so you cannot have std::function<void(std::vector<T>)> for some T still unknown, and some kind of dynamic indirect / selection can also be involved ( if you can "t SBO). The advantage of this is that since std::function is a real concrete type, you can pass it the same way as with any other object, so it can be used as a parameter of a virtual function and such things.
Basically, function pointers are simply incredibly limited and cannot really do anything interesting and make the API incredibly inflexible. Their disgusting syntax is urine in the ocean, and its abbreviation with an alias pattern is fun, but pointless.