Koenig lookup or argument dependent lookup. Most of the c++ compiler supports koenig look up. Let us understand this with below example.

we know the use of namespace key word in c++. In the above example the function g(obj) is called by using namespace wikistack. Now let us change the  above code as shown below

The above code will compile successfully even though we have not used namespace wikistack to call function g(..). how compiler does this look up? The koenig lookup feature tells the compiler to not just look at local scope, but also the namespaces that contain the argument’s type.

Koenig lookup or argument dependent lookup exercise with MCQ.

  •  will the below code compile? if yes what would be printed?

Ans: The code would be compiled and it will give output 1. The function call g(obj ) would search inside the namespace web, because compiler would look for function g(…) according to its argument.

  • will the below code compile?

Ans: No, the koenig look happens only in case of namespace.




Related Contents to follow