函数指针与回调函数

 1 #include<iostream>
 2 using namespace std;
 3 
 4 void show(int a)
 5 {
 6     cout << a <<"....";
 7 }
 8 
 9 int add(int a, int b)
10 {
11     return a + b;
12 }
13 int sub(int a, int b)
14 {
15     return a - b;
16 }
17 void  func_test(int(*p)(int, int), int a, int b)    //回调函数
18 {
19     cout<<p(a, b)<<endl;
20 }
21 
22 int main()
23 {
24     show(3);
25     void(*p)(int);    //函数指针
26     p = show;    //show函数名是地址
27     p(4);
28 
29     func_test(add,4,5);
30     func_test(sub, 4, 5);
31 
32     cout<<"hello"<<endl;
33     system("pause");
34     return 0;
35 }
原文地址:https://www.cnblogs.com/linst/p/5187170.html