namespace NS
{
class A
{
public:
A(){}
A(int){}
};
template<typename T>
void foo(T);
};
using NS::A;
class B
{
public:
B(int ii):i(ii){}
friendvoid NS::foo(A); //1
//friend void foo(NS::A); //2
private:
int i;
};
template<typename T>
void NS::foo(T)
{
::B c(10);
std::cout<<c.i<<std::endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
A t;
foo(t);
return 0;
}
Hi,my question is why i can't use the friend declaration of explanatory note 2 to replace the friend declaration NS::foo of explanatory note 1. i think the function of explanatory note 2(by Argument-Dependent Lookup) and explanatory note 1 have the same effect, am i right?(in VC2008)
If you specify unqualified-id for a friend function name then it is supposed that the function is an ordinary (non-template) function.
And the ADL is applied to arguments not to parameters.
About "And the ADL is applied to arguments not to parameters" . Why can not I think it like this:on line 20 I think because foo is a template function, NS::A is an argument for template not a parameter.And foo is a qualified-id for its template-arugment is qualified-id.
is a declaration of a friend function. So A is a declaration of its parameter that has type A. ADL is applied for function calls which uses unqualified function names.