异质链表
1 /* 异质链表 */
2
3 #include<iostream>
4 #include<QLabel>
5 #include<QPushButton>
6 using namespace std;
7
8 class base;
9
10 class linknode
11 {
12 public:
13 base *p;
14 linknode *pNext;
15
16 };
17
18 class base
19 {
20 public:
21 virtual void showit() = 0;
22
23 };
24
25 class mywindow:public base
26 {
27 public:
28 MainWindow *p;
29 mywindow()
30 {
31 p = new MainWindow;
32 }
33
34 void showit()
35 {
36 p->show();
37 }
38 };
39
40
41 class mylabel:public base
42 {
43 public:
44 QLabel *p;
45 mylabel()
46 {
47 p = new QLabel;
48 }
49
50 void showit()
51 {
52 p->show();
53 }
54 };
55
56 class mybutton:public base
57 {
58 public:
59 QPushButton *p;
60 mybutton()
61 {
62 p = new QPushButton;
63 }
64
65 void showit()
66 {
67 p->show();
68 }
69 };
70
71
72
73 int main(int argc,char *argv[])
74 {
75 QApplication a(argc,argv);
76
77 mywindow my1;
78 mylabel my2;
79 mybutton my3;
80
81 linknode l1;
82 linknode l2;
83 linknode l3;
84 l1.p = &my1;
85 l2.p = &my2;
86 l3.p = &my3;
87 l1.pNext = &l2;
88 l2.pNext = &l3;
89 l3.pNext = NULL;
90
91 linknode *p = &l1;
92 while (p!=NULL)
93 {
94 p->p->showit();
95 p = p->pNext;
96 }
97
98 cin.get();
99 }
长风破浪会有时,直挂云帆济沧海
posted on 2015-06-10 17:57 Dragon-wuxl 阅读(107) 评论(0) 收藏 举报
浙公网安备 33010602011771号