Skip to content

Instantly share code, notes, and snippets.

@hgfernan
Created July 16, 2021 15:38
Show Gist options
  • Save hgfernan/2c8e6f033e54e0353246a93c1a40dd7d to your computer and use it in GitHub Desktop.
Save hgfernan/2c8e6f033e54e0353246a93c1a40dd7d to your computer and use it in GitHub Desktop.
Invalid C++ code, showing wrong attempt to access protected and private members.
#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