-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass.cpp
76 lines (59 loc) · 1.1 KB
/
Class.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
class Base
{
public:
int m_a1;
protected:
int m_a2;
private:
int m_a3;
public:
virtual void SetValue(){}
};
class PublicClass:public Base
{
public:
void SetValue()
{
m_a1 = 1;
m_a2 = 2;
//m_a3 = 3;
}
};
class ProtectClass:protected Base
{
public:
void SetValue()
{
m_a1 = 1;
m_a2 = 2;
//m_a3 = 3;
}
};
class PrivateClass:private Base
{
public:
void SetValue()
{
m_a1 = 1;
m_a2 = 2;
//m_a3 = 3;
}
};
int main(void)
{
PublicClass Pub;
Pub.m_a1 = 1;//共有继承只能访问public成员
//Pub.m_a2 = 2;//公有继承不能访问protected成员
//Pub.m_a3 = 3;//共有继承不能访问private成员
ProtectClass Prote;
//Prote.m_a1 = 1;//保护继承不能访问所有属性的成员
//Prote.m_a2 = 2;//保护继承不能访问所有属性的成员
//Prote.m_a3 = 3;//保护继承不能访问所有属性的成员
PrivateClass Pri;
//Pri.m_a1 = 1;//私有继承不能访问所有属性的成员
//Pri.m_a2 = 2;//私有继承不能访问所有属性的成员
//Pri.m_a3 = 3;//私有继承不能访问所有属性的成员
return 0;
}