#include<iostream>
using namespace std;
void eat();
void sleep();
void hitdoudou();
void run(void (*f)());
int main()
{
int iChoice;
do
{
cout<<"Please choose (1-eat; 2-sleep; 3-hit; other-exit;)";
cin>>iChoice;
if(iChoice == 1)
{
run(eat);
}
else if(iChoice == 2)
{
run(sleep);
}
else if(iChoice == 3)
{
run(hitdoudou);
}
else
{
break;
}
}while(true);
return 0;
}
void eat()
{
cout<<"eating......"<<endl;
}
void sleep()
{
cout<<"sleeping......"<<endl;
}
void hitdoudou()
{
cout<<"hiting doudou......"<<endl;
}
void run(void (*f)())
{
(*f)();
}
运行结果