????2?????????????????????
?????????????и??????????????????????????麯?????????????漸???????????????????????????????μ??
????delete pz;            //pz is a ZooAnimal*
????delete pb;            //pb is a Bear*
????delete pp;            //pp is a Panda*
????delete pe;            //pe is a Endangered*
????????????????????Panda???????????????????????????????????????????????????????????????????Panda???????????????ε???Endangered??Bear??ZooAnimal????????????
???????????????????????????
?????????е??????????????????????????????????????????????????????????????????????????????????С??飺
1 class ZooAnimal
2 {
3 public:
4     ZooAnimal()
5     {
6         cout << "I am ZooAnimal default constructor" << endl;
7     }
8     ZooAnimal(const ZooAnimal&)
9     {
10         cout << "I am ZooAnimal copy constructor" << endl;
11     }
12     virtual ~ZooAnimal()
13     {
14         cout << "I am ZooAnimal destructor" << endl;
15     }
16     ZooAnimal& operator=(const ZooAnimal&)
17     {
18         cout << "I am ZooAnimal copy operator=" << endl;
19
20         return *this;
21     }
22 };
23 class Bear : public ZooAnimal
24 {
25 public:
26     Bear()
27     {
28         cout << "I am Bear default constructor" << endl;
29     }
30     Bear(const Bear&)
31     {
32         cout << "I am Bear copy constructor" << endl;
33     }
34     virtual ~Bear()
35     {
36         cout << "I am Bear destructor" << endl;
37     }
38     Bear& operator=(const Bear&)
39     {
40         cout << "I am Bear copy operator=" << endl;
41
42         return *this;
43     }
44 };
45 class Endangered
46 {
47 public:
48     Endangered()
49     {
50         cout << "I am Endangered default constructor" << endl;
51     }
52     Endangered(const Endangered&)
53     {
54         cout << "I am Endangered copy constructor" << endl;
55     }
56     virtual ~Endangered()
57     {
58         cout << "I am Endangered destructor" << endl;
59     }
60     Endangered& operator=(const Endangered&)
61     {
62         cout << "I am Endangered copy operator=" << endl;
63
64         return *this;
65     }
66 };
67 class Panda : public Bear?? public Endangered
68 {
69 public:
70     Panda()
71     {
72         cout << "I am Panda default constructor" << endl;
73     }
74     Panda(const Panda&)
75     {
76         cout << "I am Panda copy constructor" << endl;
77     }
78     virtual ~Panda()
79     {
80         cout << "I am Panda destructor" << endl;
81     }
82     Panda& operator=(const Panda&)
83     {
84         cout << "I am Panda copy operator=" << endl;
85
86         return *this;
87     }
88 };
????????????????????????б?????麯????????????????????2?????
int main()
{
cout << "TEST 1" << endl;
Panda ying_ying;
cout << endl << endl;
cout << "TEST 2" << endl;
Panda zing_zing = ying_ying;
cout << endl << endl;
cout << "TEST 3" << endl;
zing_zing = ying_ying;
cout << endl << endl;
return 0;
}
??????????????????TEST1??????

??????????????????????????????????????????????
?????????????????TEST2??????

??????????????????????????zing_zing???????????????????????ying_ying??????zing_zing?????????????????????????????????????????????????????????????????????TEST3??????

???????????????????????????????????????????????????и?????????и?????????????????operator=????????????????operator=????????Panda???operator=?????????????TEST3????????????????

????Panda???????????????????????????operator=??
????????ó?????????????????????????????????????????????????????????????е??????????????????????????????????????????ú??汾?????????????????????????????????????????????
???????????????????????????????

??????????????????????????????????????????????????????zing_zing??ying_ying?????????????zing_zing???????????У??4?У?????4?д???ying_ying??????????С???????ж?????????????????????????????????????????????????????
??????????????μ?????????
????????????£??????????????????Χ???????????????????????????л??????????????磺???в???Endangered??Bear/ ZooAnimal??????????????????????????????????????????????????????????????????????????????
???????磺Endangered???Bear????print????????ying_ying.print()?????±????????
???????
??????1??Panda????????????????????print?????????????????????????????????????Panda???????print??????????????????????Bear::print??Endangered::print?????á?
??????2???????????????????????????????????????????
????????????и?С????????
class ZooAnimal
{
public:
//void print(int x){}
};
class Bear : public ZooAnimal
{
public:
void print(int x){}
};
class Endangered
{
public:
void print(){}
};
class Panda : public Bear?? public Endangered
{
public:
};
????TEST1????????????Bear??Endangered????print???βα?????????
????TEST2????Bear?е?print??????ZooAnimal??????print??
????TEST3????Endangered??print?????private?????
????????????????£?????????????ying_ying.print()??ying_ying.print(1)??????????????????????????
?????????ó????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????ying_ying.Bear::print()??