C ++ name lookup -

The standard says (the brackets are mine)

In all cases listed in 3.4.1 [Search for unqualified name], the search scopes look for an ad in the order shown in each of the relevant categories ...

Why are names stored in some sort of ordered list? In the end, other than function overloading and name hiding, I think names are unique within the namespace.


UPDATE to post a comment:

I expect the compiler to keep the names defined in the container, such as unordered_set for scope and scopes related in the search chain.

I was wondering why the names had to be classified into lists for each category (which I thought were variables, typedefs, structure, functions, templates, etc.), and those lists were sorted.

+3


source to share


1 answer


The "order" in this case is not the order of the names. This is the order of the regions. Within each category, the areas are listed in a specific order (usually "inside out": from interior to exterior). This is the order in which these areas are searched. Typically, the first scope containing the specified name causes the search to stop.



+6


source







All Articles