-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmi-1a.cpp
58 lines (47 loc) · 1.03 KB
/
mi-1a.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
#include <iostream>
using namespace std;
class A
{
public:
void display()
{
cout<<"Base class A display - no msg.\n";
}
void display(const char *msg)
{
cout<<"Base class A display: " << msg << endl;
}
int Protect() const { return protect; }
void Protect(int p) { protect = p; }
protected:
int protect;
};
class B : public A
{
public:
int Protect() const { return protect; }
void Protect(int p) { protect = p; }
protected:
int protect;
};
class C : public B
{
public:
int Protect() const { return protect; }
void Protect(int p) { protect = p; }
protected:
int protect;
};
int main()
{
C c;
c.A::Protect(1);
c.B::Protect(2);
c.Protect(3);
c.display();
c.display("called from an instance of C");
cout << "c.A::protect = " << c.A::Protect() << endl;
cout << "c.B::protect = " << c.B::Protect() << endl;
cout << "c.C::protect = " << c.Protect() << endl;
return 0;
}