私有继承成员的公有化

C++语言: Codee#25741
01 /*
02    私有继承成员的公有化
03    */
04 class Pet
05 {
06 public:
07     char eat() const
08     {
09         return 'a';
10     }
11     int speak() const
12     {
13         return 2;
14     }
15     float sleep() const
16     {
17         return 3.0;
18     }
19     float sleep(int) const
20     {
21         return 4.0;
22     }
23 };
24
25 class Goldfish: Pet            //private inheritance
26 {
27 public:
28     using Pet::eat;
29     using Pet::sleep;
30 };
31
32 int main()
33 {
34     Goldfish bob;
35     bob.eat();
36     bob.sleep();
37     bob.sleep(1);
38
39     return 0;
40 }
posted @ 2012-03-07 20:33  strorehouse  阅读(183)  评论(0编辑  收藏  举报