fork download
  1. #include <iostream>
  2. class Base {
  3. protected:
  4. static int x;
  5. };
  6. int Base::x;
  7.  
  8. class DerivedA: public Base {
  9. public:
  10. DerivedA() {
  11. x = 9;
  12. }
  13. };
  14. class DerivedB: public Base {
  15. public:
  16. DerivedB() {
  17. std::cout << DerivedA::x;
  18. }
  19. };
  20. int main() {
  21. DerivedB b;
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor 'DerivedB::DerivedB()':
prog.cpp:6:5: error: 'int Base::x' is protected
 int Base::x;
     ^
prog.cpp:17:32: error: within this context
         std::cout << DerivedA::x;
                                ^
stdout
Standard output is empty