How to make a function return a pointer to a function? (C++)

user98188 picture user98188 · Jun 15, 2009 · Viewed 66.5k times · Source

I'm trying to make a function that takes a character, then returns a pointer to a function depending on what the character was. I just am not sure how to make a function return a pointer to a function.

Answer

erikkallen picture erikkallen · Jun 15, 2009
int f(char) {
    return 0;
}

int (*return_f())(char) {
    return f;
}

No, seriously, use a typedef :)