fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. namespace foo
  5. {
  6. struct Bar
  7. {
  8. int data;
  9. };
  10.  
  11. void init(Bar& bar)
  12. {
  13. bar.data = 42;
  14. }
  15. }
  16.  
  17. void init(foo::Bar& bar)
  18. {
  19. bar.data = 777;
  20. }
  21.  
  22. int main()
  23. {
  24. foo::Bar bar;
  25. init(bar) // Error! call of overloaded 'init(foo::Bar&)' is ambiguous.
  26.  
  27. std::cout << bar.data << std::endl;
  28.  
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:25:13: error: call of overloaded ‘init(foo::Bar&)’ is ambiguous
     init(bar) // Error! call of overloaded 'init(foo::Bar&)' is ambiguous.
             ^
prog.cpp:17:6: note: candidate: void init(foo::Bar&)
 void init(foo::Bar& bar)
      ^~~~
prog.cpp:11:10: note: candidate: void foo::init(foo::Bar&)
     void init(Bar& bar)
          ^~~~
stdout
Standard output is empty