I have the following code:
#include<iostream> using namespace std; typedef void (*HandlerFunc)(int, int); HandlerFunc mr; HandlerFunc mm() { return mr; } void sample(int a, int b, HandlerFunc func) { } void main() { sample(1, 2, mm); } Here I'm trying to pass a function of type HandlerFunc to another function, but I am getting an error:
Error :*: cannot convert parameter 3 from
'void (__cdecl *(void))(int,int)'to'void (__cdecl *)(int,int)'
If I type cast as sample(1, 2, (HandlerFunc)mm); everything works fine.
Can anyone tell what is the way to solve the error issue?
mm()to return the function pointer, or want to definemmas the type HandlerFunc?