fork download
  1. class base
  2. {
  3. protected:
  4. int x;
  5. };
  6.  
  7. class der: public base
  8. {
  9. void Acc(base& b)
  10. {
  11. b.x = 5; // error
  12. b.*(&der::x) = 5; // ok
  13. }
  14. };
  15.  
  16. int main () {}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void der::Acc(base&)’:
prog.cpp:4:8: error: ‘int base::x’ is protected
    int x;
        ^
prog.cpp:11:9: error: within this context
       b.x = 5;  // error
         ^
stdout
Standard output is empty