code:
namespace asd {
class A { };
void f(A &a) { }
}
void f(asd::A &a) { }
int main() {
asd::A instance;
f(instance);
return 0;
}
error:
D:\>g++ -Wall -std=c++98 -pedantic a.cpp
a.cpp: In function 'int main()':
a.cpp:10:12: error: call of overloaded 'f(asd::A&)' is ambiguous
a.cpp:10:12: note: candidates are:
a.cpp:6:6: note: void f(asd::A&)
a.cpp:3:7: note: void asd::f(asd::A&)
why does the compiler search the function 'f' in namespace asd's scope?
why is this called overloading? this is two different functions.
i would understand the error if the main funcion was like this:
int main() {
using asd::f;
asd::A instance;
f(instance);
return 0;
}
and i would get an error... but with this i dont...
this situation is same as when i do this?
std::cout << str;
// meaning 1:
std::operator<<(std::cout, str);
// meaning 2:
::operator<<(std::cout, str);