Reputation: 2534
The standard says (brackets mine)
In all the cases listed in 3.4.1 [Unqualified name lookup], the scopes are searched for a declaration in the order listed in each of the respective categories …
Why would the names be kept in some sort of ordered list(s)? After all, except for function overloading and name hiding, I think that names are unique within a namespace.
UPDATE to address a comment:
I would expect the compiler to keep the names defined in a container such as unordered_set per scope and scopes linked in a look up chain.
I was wondering why would the names be classified into lists per category (which I thought were variables, typedefs, structure like, functions, templates, etc.) and those lists further sorted.
Upvotes: 3
Views: 127
Reputation: 320371
The "order" in this case is not the order of the names. It is the order of the scopes. In each category the scopes are listed in certain order (typically "inside-out": from inner scopes to outer scopes). This is the order in which these scopes are searched. Typically, the first scope that contains the name in question causes the search to stop.
Upvotes: 6