/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved。
*文件名称:16周(指针调用函数)
*作者:王忠
*完成日期:2014.12.11
*版本号:v1.0
*
*问题描述:按提示输入,通过指针调用函数,输出
*输入描述:1.2.3.4
*程序输出:输出各类
#include <iostream>
using namespace std;
void eat();
void sleep();
void hitdoudou();
void run(void (*f)());
int main()
{
int iChoice;
do
{
cout<<"请选择(1-吃;2-睡;3-打;其他-退)";
cin>>iChoice;
if(iChoice==1)
run(eat);
else if(iChoice==2)
run(sleep);
else if(iChoice==3)
run (hitdoudou);
else if(iChoice==4)
break;
}
while(true);
return 0;
}
void eat()
{
cout<<"我吃吃吃... ..."<<endl;
}
void sleep()
{
cout<<"我睡睡... ..."<<endl;
}
void hitdoudou()
{
cout<<"我除了打还能干什么... ..."<<endl;
}
void run(void (*f)())
{
f();
}
原文:http://blog.csdn.net/wangzhongwangmin/article/details/41866241