having some trouble passing a function as a parameter of another function...
ERROR: Error 1 error C2664: 'wrapper' : cannot convert parameter 1 from 'int' to 'int (__cdecl *)(int)'
int inc( int n )
{
return n + 1 ;
}
int dec( int n )
{
return n - 1 ;
}
int wrapper( int i, int func(int) )
{
return func( i ) ;
}
int main(){
int a = 0 ;
a = wrapper( 3, inc( 3 ) ) ;
return 0 ;
}
You're passing the result of a function call inc(3)
to wrapper
, NOT a function pointer as it expects.
a = wrapper(3, &inc) ;