An important work of the compiler is to parse the name it encounters, in general, the compiler is in order to parse the name encountered, for example, the compiler encountered a function, then will generate code for this function, but if the function called another function, and this function has not been parsed, Then the compiler will make an error, such as the following example:
void H () {f ();} void F () {cout<< "F ()" <<endl;}
Because the compiler encounters H () first, but when it starts parsing H (), it finds an F () that hasn't been parsed yet, so it's an error, and if you put the definition of f () before H () there's no problem. This is the general case, the compiler should be smarter, so there is the ADL, that is, the association parameter lookup, that is, the compiler will find the function parameters associated with the scope, compare the following two examples can be found:
Example 1:
Test1.cpp
Class A {int i;public:friend void f ();}; int main (void) {f (); return 0;}
Tesp2.cpp
Class A;void F () {}
The error "F not found" appears when compiling with the following command: g++-o test1.cpp test2.cpp, take another look at the second example:
Example 2:
Test1.cpp
Class A {int i;public:friend void F (a &a);}; int main (void) {a a;f (a); return 0;}
Test2.cpp
Class A;void F (A &a) {}
Now, using the same command to compile, there is no error.
C + + name lookup with ADL