Reputation:
I've read the following (3.4.3/1):
If a :: scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that :: considers only namespaces, types, and templates whose specializations are types.
What is the lookup rule for nested-name-specifier?
For example:
#include <iostrem>
namespace A
{
int j=5;
}
int main()
{
std::cout << A::j //I assume that A will be searched as just *unqualified-name* appeared inside the function which is a member of namespace
}
The second example:
namespace A
{
namespace B
{
int j=5;
}
}
int main()
{
std::cout << A::B::j
}
Is it true that in the second example A::B will be looking as qualified name inside the namespace? I.e. we can define rules for nested-name-specifier lookup inductively. But I cant find anything like that in the standard. Is it true at all?
Upvotes: 2
Views: 161
Reputation: 171097
Yes, it's inductive, and I'd say it simply follows from the wording. First, let's add full parenthesizing based on the associativity of ::
:
(std::cout) << ((A::B)::j)
(The above is just to demonstrate how the parser understands precedence, it's not valid code).
So j
is qualified by the name A::B
. It's a qualified name, so it's looked up according to 3.4.3.
A::B
is itself a qualified name (it conforms to the syntactic form outlined by 5.1.1/8), so it is looked up according to rules for a qualified name.
Upvotes: 2