1 #include <iostream>
2 #include <list>
3 using namespace std;
4
5 class AbstractHero{
6 public:
7 virtual void Update() = 0;
8
9 };
10 class HeroA : public AbstractHero{
11 public:
12 virtual void Update( ){
13 cout<<"英雄A停止鲁"<<endl;
14 }
15 HeroA(){
16 cout <<"英雄A鲁BOSS"<<endl;
17 }
18 };
19 class HeroB : public AbstractHero{
20 public:
21 virtual void Update( ){
22
23 cout<<"英雄B停止鲁"<<endl;
24 }
25 HeroB(){
26 cout <<"英雄B鲁BOSS"<<endl;
27 }
28 };
29 class HeroC : public AbstractHero{
30 public:
31 virtual void Update( ){
32 cout<<"英雄C停止鲁"<<endl;
33 }
34 HeroC(){
35 cout <<"英雄C鲁BOSS"<<endl;
36 }
37 };
38 class HeroD : public AbstractHero{
39 public:
40 virtual void Update( ){
41
42 cout<<"英雄D停止鲁"<<endl;
43 }
44 HeroD(){
45 cout <<"英雄D鲁BOSS"<<endl;
46 }
47 };
48
49 class HeroE : public AbstractHero{
50 public:
51 virtual void Update( ){
52
53 cout<<"英雄E停止鲁"<<endl;
54 }
55 HeroE(){
56 cout <<"英雄E鲁BOSS"<<endl;
57 }
58 };
59
60 class AbstractBoss{
61 public:
62 virtual void addHero(AbstractHero* hero) = 0;
63 virtual void deleteHero(AbstractHero*hero) = 0;
64 virtual void notify() = 0;
65 };
66 class BOSSA:public AbstractBoss{
67 public:
68 list<AbstractHero*> pHeroList;
69 public:
70
71 virtual void addHero(AbstractHero* hero){
72 pHeroList.push_back(hero);
73 }
74
75 virtual void deleteHero(AbstractHero* hero){
76 pHeroList.remove(hero);
77 }
78
79 virtual void notify() {
80 for( list< AbstractHero* > :: iterator it = pHeroList.begin(); it != pHeroList.end(); it++){
81 (*it)->Update();
82 }
83 }
84 };
85 void test01(){
86 AbstractHero* heroA = new HeroA;
87 AbstractHero* heroB = new HeroB;
88 AbstractHero* heroC = new HeroC;
112
-- 插入 --
89 AbstractHero* heroD = new HeroD;
90 AbstractHero* heroE = new HeroE;
91
92 AbstractBoss*bossA = new BOSSA;
93 bossA->addHero(heroA);
94 bossA->addHero(heroB);
95 bossA->addHero(heroC);
96 bossA->addHero(heroD);
97 bossA->addHero(heroE);
98 cout << "英雄C死了..." << endl;
99 bossA->deleteHero(heroC);
100
101 cout << "Boss死了..." << endl;
102 bossA->notify();
103
104 }
105
106
107 int main(void){
108 test01();
109 return 0;
111 }