Chris Fairles wrote:
[Q: using declaration forces the file scope only in header?]
> Possible?
No, not possible. There is no "file scope". There is only
"translation unit scope". And the translation unit consists of
all the files the compiler has to scan during the processing.
Since you #include the header in your C++ source file, they both
become the translation unit. You cannot declare un-using of the
namespace, so the effect of the 'using' declaration extends to
the _end_ of the translation unit in which it's encountered.
> Take the following example:
>
> ===================
> //test1.hpp
> namespace B {
> typedef int type;
> void foo() {}
> }
> ===================
> //test.hpp
> #include "test1.hpp"
>
> namespace {
> using B::type;
> using B::foo;
> }
>
> namespace A {
> void foo(type p) { }
> }
> #endif
> ===================
> //test.cpp
> #include "test.hpp"
> int main() {
> type a;
> A::foo(a);
> foo();
> }
> ===================
>
> This compiles (with gnu gcc 4.1.1 at least). I can't seem to figure
> out what the standard says about this and why pair can be found even
> though its using decl is within an anon namespace.
>
> Given that this doesn't give the desired behavior, is there another
> technique that does? (Desired behavior being that type and foo must be
> qualified with B:: in test.cpp).
Yes. Use macros that you can 'define' and 'undef'.
>
> Chris
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask