fork download
  1. #include <iostream>
  2.  
  3. #define PRINT(val) std::cout << val << std::endl
  4. namespace sub {
  5. int value = 1;
  6. }
  7. namespace b {
  8. int alt = 3;
  9. }
  10.  
  11. namespace a {
  12. namespace b {
  13. int value = 2;
  14.  
  15. void func() {
  16. PRINT(value);
  17. PRINT(sub::value);
  18. }
  19. }
  20.  
  21. void func() {
  22. PRINT(b::value);
  23. PRINT(sub::value);
  24. //PRINT(b::alt); //no 'alt' in the closest 'b' namespace
  25. }
  26. }
  27.  
  28. int main() {
  29. PRINT("a::func");
  30. a::func();
  31. PRINT("a::b::func");
  32. a::b::func();
  33. }
  34.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
a::func
2
1
a::b::func
2
1