指向函数的指针数组

#include <iostream>
using namespace std;

#define DF(N) void N(){cout<<"function " #N " called..."<<endl; };

DF(a);DF(b);DF(c);DF(d);DF(e);DF(f);DF(g);

void (*func_table[])()={a,b,c,d,e,f,g};

int main()
{
    while(1)
    {
        cout<<"Press a key from 'a' to 'g' or q to quit"<<endl;
        char c,cr;
        cin.get(c);
        cin.get(cr);

        if(c=='q')
            break;
        if(c<'a' || c>'q')
            continue;

        (*func_table[c-'a'])();
    }
}
posted @ 2012-09-16 21:34  HelloWorld.Michael  阅读(216)  评论(0编辑  收藏  举报