-
Notifications
You must be signed in to change notification settings - Fork 1
/
inheritance.cpp
47 lines (32 loc) · 865 Bytes
/
inheritance.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
#include <iostream>
using namespace std;
class Parent {
public:
void playFunction() {
// from here I have access to everything of parent
cout << _public + _protected + _private << endl;
}
string _public = "public ";
protected:
string _protected = "protected ";
private:
string _private = "private ";
};
class Child : private Parent {
public:
// from here I only have access to _public and _private
void play() {
cout << _public + _protected << endl;
// but i do not have access to _private
// cout << _private; // compiler error
}
};
int main(void)
{
Parent parent;
parent.playFunction();
cout << parent._public << endl;
// but i cannot invoke parent._protected or parent._private
Child child;
child.play();
}