Skip to content

Commit 02118af

Browse files
authored
Create tricky-oops-problem.cpp
1 parent fb59143 commit 02118af

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tricky-oops-problem.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//g++ 5.4.0
2+
//Are private functions really private? Well...
3+
//Checkout video at: https://youtu.be/TVKsaq7Bohs
4+
#include <bits/stdc++.h>
5+
6+
using namespace std;
7+
8+
class SocialWebsite{
9+
private:
10+
protected:
11+
public:
12+
virtual void secret() {} ;
13+
};
14+
15+
class Facebook: public SocialWebsite{
16+
private:
17+
string fbPassword;
18+
19+
void secret(){
20+
cout << "The Facebook password is: " << fbPassword << endl;
21+
cout << "Its risky, but its fine to print here as it's a private function\n";
22+
}
23+
public:
24+
Facebook(string pwd) {
25+
fbPassword = pwd;
26+
}
27+
};
28+
29+
int main()
30+
{
31+
Facebook f("Rachit95@fb");
32+
33+
SocialWebsite *ptr = &f;
34+
ptr->secret();
35+
}

0 commit comments

Comments
 (0)