#include <iostream>
int add(int a, int b) {
return a + b;
}
int sub(int a, int b) {
return a - b;
}
int mymul(int a, int b) {
return a * b;
}
int mydiv(int a, int b) {
return a / b;
}
void func(int e, int d, int(*f)(int a, int b)) {
// 传入了一个int型,双参数,返回值为int的函数
std::cout << f(e, d) << std::endl;
}
int main()
{
//通过函数指针调用函数
typedef int funcPtr1(int a, int b);
funcPtr1* funcadd = add;
std::cout << funcadd(5,6) << std::endl;
typedef int (*funcPtr1sub)(int a, int b);
funcPtr1sub funcsub = sub;
std::cout << funcsub(5, 6) << std::endl;
int (*funcPtr1mymul)(int, int) = mymul;
std::cout << funcPtr1mymul(5, 6) << std::endl;
int (*funcPtr1mydiv)(int, int) = mydiv;
std::cout << funcPtr1mydiv(5, 6) << std::endl;
func(2, 3, add);
func(2, 3, funcadd);
return 0;
}
01-27
1117
03-05
1562