Created
November 9, 2016 09:28
-
-
Save kkabdol/9b3682d2c944a1b9418bd8d4b90a1c26 to your computer and use it in GitHub Desktop.
Access Modifiers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // From Kirill V. Lyadvinsky | |
| // http://stackoverflow.com/questions/860339/difference-between-private-public-and-protected-inheritance | |
| class A | |
| { | |
| public: | |
| int x; | |
| protected: | |
| int y; | |
| private: | |
| int z; | |
| }; | |
| class B : public A | |
| { | |
| // x is public | |
| // y is protected | |
| // z is not accessible from B | |
| }; | |
| class C : protected A | |
| { | |
| // x is protected | |
| // y is protected | |
| // z is not accessible from C | |
| }; | |
| class D : private A // 'private' is default for classes | |
| { | |
| // x is private | |
| // y is private | |
| // z is not accessible from D | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment