fork(1) download
  1. struct B {
  2. };
  3.  
  4. struct Klass : protected B {
  5. void foo(void) {
  6. static_cast<B*>(this); // Fine
  7. }
  8. };
  9.  
  10. struct Derived : public Klass {
  11. void bar(void) {
  12. static_cast<B*>(this); // Fine
  13. }
  14. };
  15.  
  16.  
  17. int main() {
  18. Klass k;
  19. static_cast<B*>(&k); // nope
  20. Derived d;
  21. static_cast<B*>(&d); // nope
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:19:20: error: ‘B’ is an inaccessible base of ‘Klass’
  static_cast<B*>(&k); // nope
                    ^
prog.cpp:21:20: error: ‘B’ is an inaccessible base of ‘Derived’
  static_cast<B*>(&d); // nope
                    ^
stdout
Standard output is empty