When I read the shared_ptr, I found a piece of code:
void(*)()
How to interpret it?
It is a pointer to a function type, which can be used for all the functions which have no arguments and returns void
.
For example:
void function_1() {}
void function_2() {}
void(*func_1_ptr)() = function_1; // or = &function_1;
void(*func_2_ptr)() = function_2; // or = &function_2;
Now func_1_ptr
holds the pointer to the function function_1
, and func_2_ptr
holds the pointer to function_2
.
You can make the type more intuitive by using
declaration.
using FunPtrType = void(*)();
and now you could write
FunPtrType func_1_ptr = function_1; // or = &function_1;
//Type identifier function
FunPtrType func_2_ptr = function_2; // or = &function_2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With