It seems that "using function-name" can only hide the ordinary function, but cannot hide the friend functions of the operand or the functions in the same namespace of the operand. Am I understanding this correctly?
example 1:
void swap(int)
{
}
void foo()
{
using std::swap;
int i=10,j=20;
swap(i); //compile error ,because std::swap hidden void swap(int)
}
example 2:
class Cat {
friend void swap(Cat&, Cat&);
};
void swap(Cat &lhs, Cat &rhs)
{
cout<<"call cat friend swap"<<endl;
}
class Foo
{
public:
Cat h;
};
void swap(Foo &lhs, Foo &rhs)
{
using std::swap;
swap(lhs.h, rhs.h); //compile ok. will print out
//call cat friend swap
}
Your observation is correct.
using introduces a name at the local level, which hides names in enclosing namespaces. But name search also uses argument-dependent lookup, which will still work (and might find some of the hidden names, too). If you want to find std::swap and nothing else, then write std::swap(i);.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With