Created
July 16, 2021 15:38
-
-
Save hgfernan/2c8e6f033e54e0353246a93c1a40dd7d to your computer and use it in GitHub Desktop.
Invalid C++ code, showing wrong attempt to access protected and private members.
This file contains 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
#include <iostream> | |
class EncompassingClass { | |
class ProtectedClass; | |
static class PrivateClass { | |
private: | |
int privateMember; | |
PrivateClass() { | |
privateMember = 1; | |
} | |
int sum(ProtectedClass pdc) { | |
return privateMember + pdc.protectedMember; | |
} | |
}; | |
static class ProtectedClass { | |
protected: | |
int protectedMember; | |
ProtectedClass() { | |
protectedMember = 1; | |
} | |
int sum(PrivateClass pec) { | |
return protectedMember + pec.privateMember; | |
} | |
} | |
}; | |
int main() | |
{ | |
std::cout << "Hello World!" << std::endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment