Reputation: 7
Could you explain why namespace look-up fails in that code?
namespace B {
namespace C {
int i;
}
}
namespace A {
namespace B {
void foo() {
// why does not much A::B::C
B::C::i = 3;
}
}
}
Yes, I know ::B::C::i works because we indicates global namespace but I am curious why look-up does not search outside B::C namespaces when we don't use :: before B.
Thanks in advance
Upvotes: 0
Views: 33
Reputation: 238361
Within the namespace ::A::B
, the unqualified lookup for B
finds the namespace ::A::B
rather than finding the namespace ::B
. And there is no name ::A::B::C
, so the qualified lookup for C
within the found ::A::B
fails.
Upvotes: 2