#include<iostream>
#include<string.h>
#include<vector>
using namespace std;
int add(int a,int b)//加法
{
return a+b;
}
int reduce(int a,int b)//减法
{
return a-b;
}
int ride(int a,int b)//乘法
{
return a*b;
}
int except(int a,int b)//除法
{
return a/b;
}
int main()
{
using PF=int(*)(int,int);
//定义和加减乘除四个函数相同类型的指针类型;
vector<PF> a{add,reduce,ride,except};
//定义容器a存放PF类型的指针,并将几个函数放进去;
for(int i=0;i<4;i++)
{
cout<<(a[i])(6,3)<<endl;
}
return 0;
/*输出结果
9
3
18
2
*/
}
05-09
5006

“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交