#include<iostream>
using namespace std;
void my_print(int a);
void my_print(int a,int b);
int main(void){
int x = 10 , y =20;
//1.直接不同参数调用不同重载函数
// my_print(x);
// my_print(x,y);
//2.函数指针调用
void (*pt)(int) = my_print;
pt(x); //正确
pt(x,y); //错误
return 0;
}
void my_print(int a){
cout<<"a = "<<a;
}
void my_print(int a,int b){
cout<<"a = "<<a<<" , b = "<<b;
}
函数指针调用不同重载函数
最新推荐文章于 2024-10-02 22:25:35 发布