fork(31) download
  1. #include <iostream>
  2.  
  3. int a = 10;
  4. namespace M
  5. {
  6. int a = 20;
  7. namespace N
  8. {
  9. int a = 30;
  10. void f()
  11. {
  12. int x = a; //a refers to the name inside N, same as M::N::a
  13. int y = M::a; //M::a refers to the name inside M
  14. int z = ::a; //::a refers to the name in the global namespace
  15.  
  16. std::cout << x << ", "<< y << ", " << z << std::endl; //30,20,10
  17. }
  18. }
  19. }
  20. int main()
  21. {
  22. M::N::f();
  23. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
30, 20, 10