
先看一段代码:++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
typedef (*outhead)(int a); int a(int d) { cout << "this is A" << endl; cout << d << endl; return d; } void* cou(int* a, outhead d) { cout << d(*a); return a; } int main(int argc, char** argv) { int aa = 2; cou(&aa, a); system("pause"); return 0; }
|
分析:
先定义outthead函数指针为int的别名。 (只对静态和全局有效))
我可以规定一种类型封装很多个全局函数,用一个指针函数,参数是函数指针,然后调用就好了。
近期评论