#include <iostream>
namespace ex
{
struct Test
{
};
std::istream &operator>>(std::istream &is, Test &t)
{
std::cout << "Example namespace" << std::endl;
return is;
}
}
void f(ex::Test &t);
int main()
{
ex::Test t;
std::cin >> t;
f(t);
}
std::istream &operator>>(std::istream &is, ex::Test &t)
{
std::cout << "Global namespace" << std::endl;
return is;
}
void f(ex::Test &t)
{
std::cin >> t; //error: ambiguous
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKbmFtZXNwYWNlIGV4CnsKICAgIHN0cnVjdCBUZXN0CiAgICB7CiAgICB9OwogICAgCiAgICBzdGQ6OmlzdHJlYW0gJm9wZXJhdG9yPj4oc3RkOjppc3RyZWFtICZpcywgVGVzdCAmdCkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIkV4YW1wbGUgbmFtZXNwYWNlIiA8PCBzdGQ6OmVuZGw7CiAgICAgICAgcmV0dXJuIGlzOwogICAgfQp9Cgp2b2lkIGYoZXg6OlRlc3QgJnQpOwoKaW50IG1haW4oKQp7CiAgICBleDo6VGVzdCB0OwogICAgc3RkOjpjaW4gPj4gdDsKICAgIGYodCk7Cn0KCnN0ZDo6aXN0cmVhbSAmb3BlcmF0b3I+PihzdGQ6OmlzdHJlYW0gJmlzLCBleDo6VGVzdCAmdCkKewogICAgc3RkOjpjb3V0IDw8ICJHbG9iYWwgbmFtZXNwYWNlIiA8PCBzdGQ6OmVuZGw7CiAgICByZXR1cm4gaXM7Cn0KCnZvaWQgZihleDo6VGVzdCAmdCkKewogICAgc3RkOjpjaW4gPj4gdDsgLy9lcnJvcjogYW1iaWd1b3VzCn0K
prog.cpp: In function ‘void f(ex::Test&)’:
prog.cpp:33:17: error: ambiguous overload for ‘operator>>’ in ‘std::cin >> t’
prog.cpp:33:17: note: candidates are:
prog.cpp:25:15: note: std::istream& operator>>(std::istream&, ex::Test&)
In file included from /usr/include/c++/4.7/iostream:41:0,
from prog.cpp:1:
/usr/include/c++/4.7/istream:866:5: note: std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = ex::Test] <near match>
/usr/include/c++/4.7/istream:866:5: note: no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘std::basic_istream<char>&&’
prog.cpp:9:19: note: std::istream& ex::operator>>(std::istream&, ex::Test&)