Three types of name lookups in C++ -- Sandor Dargo
Let's revisit a core concept in C++: how the compiler finds the names you use in your code. From qualified and unqualified name lookups to the special case of Argument-Dependent Lookup (ADL), understanding these mechanisms is essential for writing clear and correct C++ programs.
Three types of name lookups in C++
by Sandor Dargo
From the article:
Let’s get back to some basics this week and talk about name lookups in C++. In other words: when you refer to a symbol in your code, how does the compiler find it?
Essentially, we can differentiate between three kinds of lookups:
- Qualified name lookup
- Unqualified name lookup
- Argument-Dependent Lookup (ADL)
Let’s explore them in that order.
Qualified Name Lookup
The term qualified refers to symbols that are explicitly scoped using the
::
operator. In other words, these are names that appear to the right of a::
, such asx
ina::b::x
.Before the compiler can perform a qualified name lookup, it must first resolve the left-hand side of the
::
operator. This identifies the namespace or class being referenced.Qualified name lookup is relatively simple: it only searches the explicitly named scope. It does not search enclosing or outer scopes.