Topic: aren't using-directives idempotent?
Author: russw@io.com (Russ Williams)
Date: 1998/02/24 Raw View
I believe the following is legal, but my compiler (MSVC 5.0) complains
of an ambiguous call to overloaded function foo.
namespace Name1 {void foo();}
namespace Name2 {using namespace Name1; using namespace Name1;}
void bar()
{
Name2::foo();
}
I also get the error with the following:
namespace Name1 {void foo();}
namespace Name2 {using namespace Name1; }
namespace Name2 {using namespace Name1; }
void bar()
{
Name2::foo();
}
So are these code fragments legal or illegal? I'm thinking the
compiler is broken with respect to repeated using-directives inside
namespaces, since the following compiles fine:
namespace Name1 {void foo();}
namespace Name2 {using namespace Name1; }
void bar()
{
Name2::foo();
}
and so does the following:
namespace Name1 {void foo();}
using namespace Name1;
using namespace Name1;
void bar()
{
foo();
}
Thanks,
Russ
[ 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: clamage@Eng.sun.com (Steve Clamage)
Date: 1998/02/24 Raw View
In article 40630465@news.io.com, russw@io.com (Russ Williams) writes:
>
>I believe the following is legal, but my compiler (MSVC 5.0) complains
>of an ambiguous call to overloaded function foo.
>
>namespace Name1 {void foo();}
>namespace Name2 {using namespace Name1; using namespace Name1;}
>
>void bar()
>{
> Name2::foo();
>}
Yes, using-directives do not add any names to the declarative regions
in which they appear, and so they are idempotent. It looks like the
compiler does not treat them properly.
---
Steve Clamage, stephen.clamage@sun.com
[ 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 ]