fork download
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5. protected:
  6. int a_;
  7. virtual bool SomeProtectedMethod() { return true; }
  8. };
  9.  
  10. class B: public A
  11. {
  12. public:
  13. void print() { std::cout << a_ << std::endl; }
  14. };
  15.  
  16. class C: public B
  17. {
  18. public:
  19. void print2(A * p) { std::cout << p->SomeProtectedMethod() << std::endl; }
  20. };
  21.  
  22. int main(int argc, char* argv[])
  23. {
  24. A a;
  25. B b;
  26. C c;
  27. b.print();
  28. c.print2(&a);
  29.  
  30. return 0;
  31. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void C::print2(A*)’:
prog.cpp:7: error: ‘virtual bool A::SomeProtectedMethod()’ is protected
prog.cpp:19: error: within this context
stdout

Standard output is empty