fork download
  1. #include <iostream>
  2.  
  3. namespace name
  4. {
  5. void func();
  6. }
  7. void name::func()
  8. {
  9.  
  10. int x = 1;
  11. std::cout << x;
  12. }
  13. namespace person
  14. {
  15. void func();
  16. }
  17. void person::func()
  18. {
  19. int x = 2;
  20. std::cout << x;
  21. }
  22.  
  23. using namespace name;
  24. using namespace person;
  25.  
  26. int main()
  27. {
  28. func();
  29. //what would x equal 1 or 2?
  30. //what happens when two namespaces initializes same variables or functions?
  31. //you get an error!!
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:28:10: error: call of overloaded ‘func()’ is ambiguous
     func();
          ^
prog.cpp:28:10: note: candidates are:
prog.cpp:17:6: note: void person::func()
 void person::func()
      ^
prog.cpp:7:6: note: void name::func()
 void name::func()
      ^
stdout
Standard output is empty