fork download
  1. #include <iostream>
  2.  
  3. class X {
  4. private:
  5. struct B {
  6. B() { y = 2012; }
  7. int y;
  8. };
  9. B b;
  10.  
  11. public:
  12. X() {}
  13. B& GetB() { return b; }
  14. };
  15.  
  16. int main()
  17. {
  18. X x;
  19. auto& g = x.GetB();
  20. // Why do we have access to X::B here?
  21. std::cout << g.y;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
2012