You are allowed to return a function pointer, and the correct syntax is as follows:
void (*myfn())(int) { }
Full example:
#include <cstdio> void retfn(int) { printf( "retfn\n" ); } void (*callfn())(int) { printf( "callfn\n" ); return retfn; } int main() { callfn()(1); // Get back retfn and call it immediately }
What compiles and runs as follows:
$ g++ myfn.cpp && ./a.out callfn retfn
If anyone has a good explanation why the g ++ error message suggests this is not possible, I would be interested to hear it.
source share