1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> using namespace std; class A { protected: void f() { cout << "A::f()" << endl; } }; class B : private A {}; class C : B { public: C() { f(); } //A::f is inaccessible }; int main() { C c; return 0; } |
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIEEKewogICBwcm90ZWN0ZWQ6CiAgICB2b2lkIGYoKSB7IGNvdXQgPDwgIkE6OmYoKSIgPDwgZW5kbDsgfQp9OwoKY2xhc3MgQiA6IHByaXZhdGUgQSB7fTsKCmNsYXNzIEMgOiBCIAp7CiAgcHVibGljOgogICAgICAgICBDKCkgeyBmKCk7IH0gLy9BOjpmIGlzIGluYWNjZXNzaWJsZQp9OwoKaW50IG1haW4oKSB7CglDIGM7CglyZXR1cm4gMDsKfQ==
prog.cpp: In constructor ‘C::C()’: prog.cpp:8: error: ‘void A::f()’ is protected prog.cpp:16: error: within this context prog.cpp:8: error: ‘void A::f()’ is protected prog.cpp:16: error: within this context prog.cpp:16: error: ‘A’ is not an accessible base of ‘C’
-
result: Compilation error (maybe you wish to see an example for C++ 4.7.2)


