#include <iostream>
#include <vector>
using namespace std;//start
int add(int const &a, int const &b)
{
int temp = 0;
temp = a + b;
return temp;
}
int sub(int const &a, int const &b)
{
int temp = 0;
temp = a - b;
return temp;
}
int mult(int const &a, int const &b)
{
int temp = 0;
temp = a * b;
return temp;
}
int divi(int const &a, int const &b)
{
int temp = 0;
temp = a / b;
return temp;
}
int main()
{
int(*p) (int const &a, int const &b);
p = add;//p 为函数指针 ,指向add 函数
//p = &add; 与上面句 是等效的
vector <int(*) (int const &a, int const &b)> v1;//v1容器存放着 元素 为 函数指针,(函数的形参int const &a, int const &b。。。返回值为int)
int(*pb[4])(int const &a, int const &b) = {add,sub,mult,divi};//pb 为 函数指针数组
v1.push_back(add);
//v1.push_back(pb[0]) 与上面句 是等效的
int bbb = pb[0](1, 2);
cout << bbb << endl;//3
getchar();
return 0;
}