Namespaces have far-reaching implications for modern C + + programming and design. Some of these effects are straightforward and obvious, such as using declarations and using directives, and names that are qualified by namespace scopes. However, namespaces have some very basic and important effects that are less grammatical. An argument-dependent lookup (Argument Dependent lookup ADL) is one of them. Like many C + + features, ADL can become complex in some situations, but in general it is fairly straightforward to use and solves more problems than it introduces.
The idea behind ADL is very simple. When looking for a function name in a function call expression, the compiler is also checked in the namespace containing the type of the function call argument. As an example, consider the following code:
#include <iostream>namespaceorg_semantics{classx{}; voidFConstX &){} voidG (X *) {} Xoperator+(Constx& A,Constx&b) { returnA//added for normal compilation } classstring{}; Std::ostreamoperator<< (Std::ostream &a,ConstString &b) { returnA//added for normal compilation }};intG (org_semantics::x*a) { return 0;//added for normal compilation}voidAfunc () {org_semantics::x A; f (a);//call Org_semantics::f argument dependent lookup//I use VC implementation of the effect is reversed, here error, undefinedg (&a);//Error! has ambiguous nature//error C2668: ' G ' ambiguous call to overloaded function //I use VC to achieve the effect is reversed, compiled here through A=a+a;//Call org_semantics::operator+}intMain () {return 0;}
Normal find does not find
Argument dependent lookup [clause]----C + + must know required