c++ - Make function pointer from an already declared function -
i have function declared int __stdcall myfunction(int param, int param);
, need type of pointer function in macro or template when name passed parameter.
is possible in c++ or have rewrite function signature myself?
you can make type alias function pointer (to decays, or returned address-of operator) following way:
#include <iostream> int myfunction(int param, int param1) { std::cout << param << " " << param1 << std::endl; return 0; } using myfunction_ptr_t = std::decay<decltype(myfunction)>::type; // or using myfunction_ptr_t = decltype(&myfunction); // or using myfunction_ptr_t = decltype(myfunction) *; int main() { myfunction_ptr_t myfunction_ptr = myfunction; myfunction_ptr(1, 2); }
this example should rather use auto
specifier (since c++ 11):
auto myfunction_ptr = myfunction;
but won't in non-deducible context.
Comments
Post a Comment