https://www.zhihu.com/question/19801131

1
2
3
4
5
6
7
8
9
10
11
12
13
def double(x):
return x * 2
def quadruple(x):
return x * 4
def getOddNumber(k, getEvenNumber):
return getEvenNumber(k)
print getOddNumber(2,double)
print getOddNumber(2,quadruple)

l.h

1
2
#include <cstdio>
void fill_screen(int (*some_func)(void)) {printf("%d\n",some_func());}

c.cpp

1
2
3
4
5
6
7
8
9
10
11
12
#include "l.h"
int draw_this_way() {return 0;}
int draw_that_way() {return 1;}
int draw_yet_another_way() {return 2;}
int main() {
fill_screen(&draw_this_way);
fill_screen(&draw_that_way);
fill_screen(&draw_yet_another_way);
return 0;
}