//============================================= //f0508FuncPointerVector.cpp //函数指针向量实现菜单驱动函数调用 //by leo //5.29.2011 //============================================= #include<iostream> #include<vector> using namespace std; //--------------------------------------------- typedef void (*MenuFun) (); void f1(){cout<<"good/n";}; void f2(){cout<<"better/n";}; void f3(){cout<<"best/n";}; //--------------------------------------------- int main() { vector<MenuFun> fun(3); fun[0] = f1; fun[1] = f2; fun[2] = f3; for(int choice=1; choice;) { cout<<"1--good/n" <<"2--better/n" <<"3--best/n" <<"0--exit/n" <<"enter your choice:/n"; cin>>choice; if(choice>0 && choice<4) fun[choice-1](); else if(!choice) return 0; else cout<<"bad command!/n"; } } //=============================================