您的位置:首页 > 编程语言 > C语言/C++

C++ 函数指针批处理

2016-03-30 10:25 288 查看
#include<iostream>
using namespace std;
int i =0;

void init_cpu()
{
cout<<++i<<" "<<__func__<<endl;
}
void init_serial()
{
cout<<++i<<" "<<__func__<<endl;
}
void init_usb()
{
cout<<++i<<" "<<__func__<<endl;
}
void init_sd()
{
cout<<++i<<" "<<__func__<<endl;
}
void init_camera()
{
cout<<++i<<" "<<__func__<<endl;
}
typedef void(*INITF)();
INITF initf[]={
init_cpu,init_serial,
init_usb,init_camera,NULL
};
int intf[]={1,2,3,4,0};
int main()
{
INITF * p = initf;
for(;*p;p++)
(*p)();
int * k = intf;
for(;*k;k++)
cout<<*k<<" ";
cout<<endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: