forked from zsw5/Cpp_Primer_Answers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise15_20.cpp
67 lines (55 loc) · 1 KB
/
exercise15_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
65
66
67
#include <iostream>
#include <string>
#include "exercise15_5.h"
#include "bulk_quote.h"
#include "limit_quote.h"
#include "disc_quote.h"
class Base
{
public:
void pub_mem(); // public member
protected:
int prot_mem; // protected member
private:
char priv_mem; // private member
};
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;
}