Re: Using directive/declaration and the global namespace
"David Wilkinson" wrote:
[...] if you look at Stroudstrup, 3rd edition, page 181,
he gives an example which (I think) is exactly what I did
with the namespace N3, saying that the using declaration
disabiguates the duplicated class in the two directives.
So I was very puzzled when it did not work for me, and it
took me a while to realize that it was because the
difference was that I was trying to do it in the global
namespace.
Indeed, according to Stroustrup `using N2::A' declaration
should take precedence ver all other names:
"When looking into a namespace, names explicitly declared
there (including names declared by using-declarations) take
priority over names made accessible in another scope by a
using-directive (see also ?C.10.1)."
Also, both Stroustrup and C++ Standard emphasize that global
space is "just another namespace" without any special
privileges. After playing a little bit with the code I
noticed that by specifying global namespace for `A' I could
solve ambiguity:
using namespace N1; // directive
using namespace N2; // directive
using N2::A; // declaration
void f()
{
::A a; // <- global scope
a.F();
}
So, when qualified name is used, then no ambiguity exists.
Currently I don't have reasonable answer for this. I'll try
to investigate it more tomorrow.
Alex