fork(1) download
  1. #include <iostream>
  2.  
  3. int avar = 10;
  4. namespace Some
  5. {
  6. int avar = 20;
  7. namespace Thing
  8. {
  9. int avar = 30;
  10. void Funky()
  11. {
  12. int a = avar; // a refers to the name inside Thing (Line 9), same as Some::Thing::avar
  13. int b = Some::avar; // Some::avar refers to the name inside Some (Line 6)
  14. int c = ::avar; // ::avar refers to the name in the global namespace (Line)
  15. bool d = (10 == ::avar); // Compare the hard-coded value with the value of the global avar (true)
  16. bool e = (avar == ::avar); // Compare local avar with the global avar (false)
  17. bool f = (avar == Some::Thing::avar); // Compare local avar with itself (true)
  18.  
  19. std::cout << a << ", "<< b << ", " << c << ", " << d << ", " << e << ", " << f << std::endl; // 30,20,10,1,0,1
  20. }
  21. }
  22. }
  23. int main()
  24. {
  25. Some::Thing::Funky();
  26. }
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
30, 20, 10, 1, 0, 1