Topic: Question re using declaration/directive
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/12/11 Raw View
In article 00032mC@iquest.net, Scott Stevens <wss@iquest.net> writes:
>What errors (if any) should result from attempting to compile the following?
> namespace Foo
> {
> class Bar
> {
> int i;
> };
> }
> using namespace Foo; // using-directive
> using Foo::Bar; // using-declaration
> Bar bar1;
>My compiler complains "'Bar' : ambiguous symbol" on the last line.
>Commenting
>out either the using directive or the using-declaration eliminates the error
>message.
First, let's note that early implementations of namespaces are going to
be plagued by uncertainties in the language definition, and by changes
in the definition. So I wouldn't be surprised to find inconsistent
behavior among implementations, and the determination of what is "correct"
behavior tends to change with time :-(
According to how I read the September draft, the using-directive says
that names in Foo are visible without qualification, but those names
are not introduced into the declarative region (file scope in this case).
Next, the using-declaration introduces the class name Bar from namespace
Foo into file scope. The name was already visible, but now is a unique
type name in this scope.
Finally, consider the definition of bar1 as type Bar. There is only one Bar
in the translation unit, and all uses of "Bar" refer to the same item.
So I would say that that the code is OK according to the latest draft
standard. I have not attempted to determine whether the code would be
in error according to an earlier draft.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]