您的位置:首页 > 其它

接受int形参(double,,等等)返回int(...);并且一个vector对象保存指向这些函数的指针;进行加减乘除;输出结果

2017-03-13 09:16 447 查看
#include <bits/stdc++.h>
using namespace std;
int f1(int a,int b)
{
return a+b;
}
int f2(int a,int b)
{
return a-b;
}
int f3(int a,int b)
{
return a*b;
}
int f4(int a,int b)
{
return a/b;
}
int main()
{

vector<int(*)(int,int)> v;
v.push_back(f1);
v.push_back(f2);
v.push_back(f3);
v.push_back(f4);

cout << v[0](1,2) << endl;
cout <<v[1](1,2) << endl;
cout << v[2](1,2) << endl;
cout << v[3](2,1) << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  函数指针 指针
相关文章推荐