1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| #define _CRT_SECURE_NO_WARNINGS #include <iostream>
using namespace std;
typedef void(TIPS_FUNC)(void);
struct tips { char from[64]; char to[64]; TIPS_FUNC *fp; };
void open_tips(struct tips * tp) { cout << "打开了锦囊" << endl; cout << "此锦囊是由" << tp->from << ", 写给" << tp->to << endl; cout << "内容是" << endl; tp->fp(); }
void tips_1(void) { cout << "一到东吴就大张旗鼓找乔国老" << endl; }
void tips_2(void) { cout << "骗刘备 操作压境" << endl; }
void tips_3(void) { cout << "找孙尚香求救" << endl; }
void tips_4(void) { cout << "你们就死在东吴把" << endl; }
struct tips* create_tips(char *from, char *to, TIPS_FUNC *fp) { struct tips *tp = (struct tips*)malloc(sizeof(struct tips)); if (tp == NULL) { return NULL; } strcpy(tp->from, from); strcpy(tp->to, to); tp->fp = fp;
return tp; }
void destory_tips(struct tips * tp) { if (tp != NULL) { free(tp); } }
int main(void) { struct tips * tp1 = create_tips("孔明", "赵云", tips_1); struct tips * tp2 = create_tips("孔明", "赵云", tips_2); struct tips * tp3 = create_tips("孔明", "赵云", tips_3); struct tips *tp4= create_tips("庞统", "赵云", tips_4);
cout << "刚来到 东吴境内 ,打开了第一个锦囊" << endl; open_tips(tp1);
cout << "刘备乐不思蜀 ,打开第二个锦囊 " << endl;
open_tips(tp2);
cout << "孙权追杀刘备, 打开第三个锦囊" << endl; open_tips(tp3); cout << "赵云发现 抵挡不住 军队,想到了庞统的最后一个锦囊 打开了" << endl;
open_tips(tp4);
destory_tips(tp1); destory_tips(tp2); destory_tips(tp3); destory_tips(tp4);
return 0; }
|