Re: enum breaks the namespace

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 01/17/05


Date: Mon, 17 Jan 2005 10:33:43 -0600

Paavo Helde wrote:

>MS Visual C++ 7.1 happily compiles the following:
>
>namespace First {
> class A {};
>}
>
>namespace Second {
> using namespace First;
> enum foo {bar};
>}
>
>int main() {
> A a; // Class A should not be visible!
>}
>
>
>Both Comeau online and gcc reject the code. When commenting out the "enum"
>line, also MSVC rejects the code. It seems like an enum definition exports
>the "using namespace" directive out of the second namespace!
>
>Is this a known bug? And is there some workaround? I would not like to leak
>names all over the place, but in the same time I would like to make the
>First library automatically accessible to the clients who have the "using
>namespace Second;" directive in their code.

This appears to be fixed in the Whidbey beta. For VC7.1, I don't know of any
workaround, but then I tend not to use using-directives as above.

-- 
Doug Harrison
Microsoft MVP - Visual C++