I defined a getline
function inside my own namespace:
namespace pru{
class A{
friend std::istream& getline(std::istream& in, A& a)
{
std::cout << "getline\n";
return in;
}
};
And then call it in the main as usual:
pru::A a;
pru::getline(std::cin, a);
But surprisingly it doesn't compile. Both g++ and clang gives the same error:
'getline' is not a member of 'pru'
But if I call getline
without pru
:
pru::A a;
getline(std::cin, a);
it compiles!!! Why? getline is a member of pru!