#include"iostream"
using namespace std;
typedef void(*pfun)();
void fun1(){
cout<<"this is 1"<<endl;
}
void fun2(){
cout<<"this is 2"<<endl;
}
//函数接口
void funs(pfun p)
{
(*p)();
}
int main()
{
funs(fun1);
funs(fun2);
return 1;
}C/C++函数实现接口
最新推荐文章于 2024-11-28 21:29:41 发布
本文通过一个简单的C++程序介绍了如何使用函数指针来调用不同的函数。该程序定义了两个函数fun1和fun2,并通过函数指针pfun来传递这两个函数的地址到另一个函数funs中进行调用。

1万+

被折叠的 条评论
为什么被折叠?



