3

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 this doesn't work. I don't want a solution like

std::function<void(int)>

Because mt function pointer definition is much more complicated

user972014
  • 3,296
  • 6
  • 49
  • 89
  • 1
    `std::function` wants a function type as its template parameter - which is not the same as pointer-to-function type. There's a difference between `void(int)` and `void(*)(int)`. `PFN_func` is a typedef for the latter. – Igor Tandetnik Sep 09 '14 at 21:03

1 Answers1

7

You could do this:

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

Removing the pointer from void (*)(int) gives the function type void(int).

For the case of a general callable, see Is it possible to figure out the parameter type and return type of a lambda?

Community
  • 1
  • 1
Brian Bi
  • 111,498
  • 10
  • 176
  • 312