#include<iostream>
using namespace std;
int fun(int a){
cout << "fun1" << endl;
cout << "a = " << a << endl;
}
int func(int a,int b){
cout << "fun2" << endl;
cout << "a = " << a << "b = " << b << endl;
}
//1. 定义之中函数类型
typedef int(MY_FUNC)(int,int);
//2.顶一个指向之中函数类型的指针类型
typedef int(*MY_FUNC_P)(int ,int);
int main(){
//第一种方式
MY_FUNC * fp = NULL;
fp = func;
fp(10,20);
//第二种方式
MY_FUNC_p fp1 = NULL;
fp1 = func;
fp1(10,20);
//第三种方式:最常用
//fun(1);
int(*fp)(int,int) = NULL;
fp = func;
fun(1,2);
//fp(1,2);
return 0;
}
c++之 函数重载与函数指针
猜你喜欢
转载自blog.csdn.net/weixin_46381608/article/details/108391656
今日推荐
周排行