您的位置:首页 > 编程语言 > C语言/C++

C++编程思想 第五章隐藏实现 习题

2013-07-21 21:53 344 查看
5-1

 C++ Code 
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

#include <iostream>
#include <string>
#include "myhead.h"
#include <cstdio>
using namespace std ;

class sharp

{
public:

    string a;
protected:

    string b;
private:

    string c;
public:

    sharp()//这里必须是public

    {

        //this->inital();
        this->a="public:";

        this->b ="protected:";

        this->c ="private:";

    }

    

};
int main(void)

{

    sharp check;

    cout<<check.a;

    cout<<check.b;

    check<<check.c;

    system("pause");

}

5-3



 

5-4



 

5-6

 C++ Code 
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

#include <iostream>
using namespace std;

class hen

{
public:

    class next

    {

    public:

        class egg

        {

        public:

            void dispaly(void)

            {

                cout<<"egg"<<endl;

            }

        };

        void dispaly(void)

        {

            cout<<"next"<<endl;

        }

    };

    void dispaly(void)

    {

        cout<<"hen"<<endl;

    }

};

void main(void)

{

    //类的嵌套  
    hen dage;

    //二级嵌套
    hen::next jidan;

    //三级嵌套
    hen::next::egg fuck;

    dage.dispaly();

    jidan.dispaly();

    fuck.dispaly();

    system("pause");

}
 

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: