Cast function pointer to functor in C ++

I have a function pointer type imported from another .hpp file. Something like:

typedef void (*PFN_func)(int i);

      

I want to create a functor of the same type:

std::function<PFN_func>

      

But it doesn't work. I don't want a solution like

std::function<void(int)>

      

Since the definition of a function pointer mt is much more complicated

+3


source to share


1 answer


You can do it:

std::function<std::remove_pointer<PFN_func>::type>

      



Removing the pointer from void (*)(int)

gives the type of the function void(int)

.

In the case of a generic call, see Is it possible to determine the parameter type and return type of a lambda?

+7


source







All Articles