I have
struct A { void ohai() {} };
struct B: protected A {};
struct C: private A { friend int main();};
struct D: B { void test() { ohai();} };
struct E: C { void test() { ohai();} };
int main() {
A().ohai();
B().ohai();
C().ohai();
D().ohai();
return 0;
}
However, I get the errors
error: ‘void A::ohai()’ is inaccessible
struct A { void ohai() {} };
^
main.cpp:20:11: error: within this context
B().ohai();
^
main.cpp:8:17: error: ‘void A::ohai()’ is inaccessible
struct A { void ohai() {} };
^
main.cpp:22:11: error: within this context
D().ohai();
I don't understand these errors. Because B
inherits from A
is protected, shouldn't it have access to Ohai
? When I changed the inheritance to public
, I got no errors
EDIT: Difference between private, public, and protected inheritance does not answer my question. According to that link, B
should inherit ohai
according to protected inheritance