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

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  
#include  
#include   "myhead.h"
#include  
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<     cout<     check<     system(
"pause" );
}

5-3

C++编程思想 第五章隐藏实现 习题_第1张图片

 

5-4

C++编程思想 第五章隐藏实现 习题_第2张图片

 

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  
using   namespace  std;

class  hen
{
public :
    
class  next
    {
    
public :
        
class  egg
        {
        
public :
            
void  dispaly( void )
            {
                cout<<
"egg" <             }
        };
        
void  dispaly( void )
        {
            cout<<
"next" <         }
    };

    
void  dispaly( void )
    {
        cout<<
"hen" <     }
};


void  main( void )
{
    
//类的嵌套  
    hen dage;
    
//二级嵌套
    hen::next jidan;
    
//三级嵌套
    hen::next::egg fuck;
    dage.dispaly();
    jidan.dispaly();
    fuck.dispaly();
    system(
"pause" );
}

 

 

 

 

 

你可能感兴趣的:(C++编程思想 第五章隐藏实现 习题)