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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -