/
ex15.20.cpp
65 lines (50 loc) · 891 Bytes
/
ex15.20.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
#include <iostream>
class Base
{
public:
void pub_mem();
protected:
int prot_mem();
private:
char priv_mem();
};
struct Pub_Derv : public Base
{
void memfcn(Base& b) {b = *this; }
};
struct Priv_Derv : private Base
{
void memfcn(Base& b) {b = *this; }
};
struct Prot_Derv : protected Base
{
void memfcn(Base& b) {b = *this; }
};
struct Derived_from_Public : public Pub_Derv
{
void memfcn(Base& b) {b = *this; }
};
struct Derived_from_Private : public Priv_Derv
{
//void memfcn(Base& b) {b = *this; }
};
struct Derived_from_Protected : public Prot_Derv
{
void memfcn(Base& b) {b = *this; }
};
int main()
{
Pub_Derv d1;
Base* p=&d1;
Priv_Derv d2;
p=&d2;
Prot_Derv d3;
p=&d3;
Derived_from_Public dd1;
p=&dd1;
Derived_from_Private dd2;
p=&dd2;
Derived_from_Protected dd3;
p=&dd3;
return 0;
}