fork download
  1. class Encapsulator
  2. {
  3. protected:
  4. int i;
  5. public:
  6. Encapsulator(int v) : i(v) {}
  7. };
  8.  
  9. Encapsulator f(int x) { return x + 2; }
  10.  
  11. #include <iostream>
  12. int main( void )
  13. {
  14. Encapsulator e = f(7);
  15. // forbidden: std::cout << e.i << std::endl;
  16. struct Gimme : Encapsulator { static int Encapsulator::* it() { return &Gimme::i; } };
  17. int Encapsulator::*pi = Gimme::it();
  18. std::cout << e.*pi << std::endl;
  19. }
  20.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
9