-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNameHiding.cpp
59 lines (59 loc) · 1.13 KB
/
NameHiding.cpp
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
//#include<iostream>
//#include<string>
//using namespace std;
//class PetFood{
//public:
// virtual string foodType()const=0;
//};
//class Pet{
//public:
// virtual string type()const=0;
// virtual PetFood *eats()=0;
//};
//class Bird:public Pet{
//public:
// string type()const{return "Bird";}
// class BirdFood:public PetFood{
// public:
// string foodType() const{
// return "Bird food";
// }
// };
// PetFood*eats()
// {
// return &bf;
// }
// private:
// BirdFood bf;
//};
//class Cat:public Pet{
//public:
// string type() const {return "Cat";}
// class CatFood:public PetFood{
// public:
// string foodType() const{return "Birds";}
// };
// CatFood* eats(){return &cf;}
//private:
// CatFood cf;
//};
//int main()
//{
// Bird b;
// Cat c;
// Pet*p[]={&b,&c};
// for(int i=0;i<sizeof(p)/sizeof(*p);i++)
// {
// cout<<p[i]->type()<<"eats"
// <<p[i]->eats()->foodType()<<endl;
// Cat::CatFood*cf=c.eats();
// Bird::BirdFood*bf=dynamic_cast<Bird::BirdFood*>(b.eats());
// /*bf=dynamic_cast<Bird::BirdFood*>(b.eats());*///ÏòÏÂÀàÐÍת»¯£¬dynamic_cast<>
// }
//}
//
//
//
//
//
//