fork download
  1. struct base {};
  2.  
  3. class outer: public base
  4. {
  5. private:
  6. enum { some=42, special=67, implementation=999, details=-13 };
  7.  
  8. public:
  9. struct inner
  10. {
  11. protected:
  12. void foo() { int can_usethis = special + implementation + details; }
  13. };
  14.  
  15. outer() : _inner() { }
  16.  
  17. void call_inner(inner& i) const
  18. {
  19. //i.foo(); // fails (protected)
  20. }
  21.  
  22. void call_inner() const
  23. {
  24. //_inner.foo(); // fails (protected)
  25. }
  26.  
  27. private:
  28. inner _inner;
  29. };
  30.  
  31.  
  32. int main()
  33. {
  34. outer o;
  35. outer::inner i;
  36.  
  37. // i.foo(); // fails: protected
  38. o.call_inner(i);
  39. }
  40.  
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void outer::inner::foo()’:
prog.cpp:12: warning: unused variable ‘can_usethis’
stdout
Standard output is empty