/**
* 功能:指向函数的指针数组
* 时间:2014年8月14日07:24:46
* 作者:cutter_point
*/
#include<iostream>
#include<cstdlib>
using namespace std;
//这里N就是函数名,而DF(N)就代表了后面的N函数,N可以变
#define DF(N) void N() {cout<<"function "#N" is called"<<endl;}
DF(a);DF(b);DF(c);DF(d);DF(e);DF(f);DF(g); //这就相当于7个函数
void (*func_table[])()={a,b,c,d,e,f,g};
int main()
{
while(1)
{
cout<<"输入两个字符在‘a’到'g'之间,q是退出"<<endl;
char c1, c2, c3;
cin>>c1>>c2;
c3='q';
//判定是否应该退出程序
if(c1 == 'q')
break;
if(c1<'a' || c1>'g')
continue;
(*func_table[c1-'a'])();
cout<<"#c1:"<<c1<<"\t#c2:"<<c2<<endl;
}
system("pause");
return 0;
}
【ThinkingInC++】18、指向函数的指针数组,布布扣,bubuko.com
原文地址:http://blog.csdn.net/cutter_point/article/details/38552869