C++ 函数指针批处理

#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;
}
原文地址:https://www.cnblogs.com/Sico2Sico/p/5384264.html