Topic: Namespace query
Author: sanjayp@ddi.com
Date: 1999/04/02 Raw View
I have a piece of code:
int i;
namespace A {
namespace B {
int i;
}
using namespace B;
}
namespace C {
using namespace A;
int j = i;
}
I think there are only two possibilities:
1) C::j is initialized with A::B::i. If you read 7.3.4 para 2 and apply it
separately to the two using directives then A::B::i appears as if it was
declared in A because of the using directive in A. And then since A::i would
hide ::i that one will be chosen by the lookup.
2) This piece of code is illegal because there is an ambiguity between ::i and
A::B::i. If you follow 7.3.4 para 3 literally then we see both the using
directives in C and then both the i's appear as if they were declared at
global scope. That would create an ambiguity.
What is the correct explanation?
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: ajonas@my-dejanews.com
Date: 1999/04/04 Raw View
sanjayp
> I have a piece of code:
int i;
namespace A
{
namespace B // (*)
{
int i;
}
using namespace B;
}
namespace C
{
using namespace A; // See 7.3.4 Para 3, transitivity
// implies using namespace B (**) aswell
int j = i; (***)
}
>
> I think there are only two possibilities:
>
> 1) C::j is initialized with A::B::i. If you read 7.3.4 para 2 ...
> 2) This piece of code is illegal ...
> What is the correct explanation?
Case 2 is correct.
Reading Para 7.3.4 Para 2
For the purposes of unqualified lookup, the names 'imported' from (**) are
imported into the global namespace. ie. Into the closest enclosing namespace
that contains both the using-directive (**) and the namespace
declaration (*).
Thus (***) is ambiguous.
--
Alex Jonas
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]