fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. protected:
  6. int x;
  7. };
  8.  
  9. class B {
  10. public:
  11. static void m() {
  12. A foo;
  13. cout << foo.x << endl;
  14. }
  15. };
  16.  
  17. int main() {
  18. B::m();
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static void B::m()’:
prog.cpp:13:15: error: ‘int A::x’ is protected within this context
   cout << foo.x << endl;
               ^
prog.cpp:6:6: note: declared protected here
  int x;
      ^
stdout
Standard output is empty