It works if it has a void parameter. |
No, it doesn't work. Or better, it works only if you are lucky.
See cire's answer (even for main returning int).
You should change the line
typedef int (__stdcall *f_funci)();
to
typedef void (*f_funci)();
and the cast is not needed.
Also, void is not a parameter, but it indicates no parameters. It is a C-ism, in C++ you should use
void f()
instead.
Also, please use code tags to improve readability. See
http://www.cplusplus.com/articles/jEywvCM9/
To solve your issue, the following example might help you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
typedef void (*f_funci)();
typedef void(*f_funci_with_param)(int);
void f()
{
std::cout << "hello\n";
}
void f(int num)
{
std::cout << "hello " << num << "\n";
}
int main()
{
f_funci z = f;
z();
f_funci_with_param z_with_param = f;
z_with_param(3);
return 0;
}
|
Notice I used the same function name for both: the compiler chooses the right f function.
If your compiler cannot do it, you should use different names for the 2 functions.