fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base
  5. {
  6. protected:
  7. int x{ 0 };
  8. };
  9.  
  10. class DerivedClass1 : public Base
  11. {
  12. void test() {
  13. std::cout<<x<<std::endl;
  14. }
  15. private:
  16. using Base::x;
  17.  
  18. };
  19.  
  20. class DerivedClass2 : public DerivedClass1
  21. {
  22. public:
  23. int getX() const
  24. {
  25. return x;
  26. }
  27. };
  28.  
  29. int main()
  30. {
  31. DerivedClass2 d2{};
  32. int x{ d2.getX() };
  33. return 0;
  34. }
  35.  
  36.  
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘int DerivedClass2::getX() const’:
prog.cpp:25:16: error: ‘int Base::x’ is protected within this context
         return x;
                ^
prog.cpp:7:14: note: declared protected here
     int x{ 0 };
              ^
stdout
Standard output is empty