namespace illogic or bug?

Carlo Wood carlo@alinoe.com
Tue Jun 27 02:48:00 GMT 2000


Hiya,

I did run into a weird behaviour of namespace and I was wondering
if this is the way the Standard meant it to be, or that it is a bug...

Consider the following program:

------------------------------
namespace A {
  int i;
};

namespace AB {
  using namespace A;
  int i;
};

namespace C {
  using namespace AB;
};

int main(void)
{
  C::i = 1;
  return 0;
}
------------------------------

This compiles fine, as it should.
C::i is taken as AB::i, which is directly declared in AB and thus hides A::i.

Now change main() to read:

int main(void)
{
  using namespace C;
  i = 3;
  j = 4;
  return 0;
}

This does NOT compile because:

namespace3.cc:18: use of `i' is ambiguous
namespace3.cc:8:   first declared as `int AB::i' here
namespace3.cc:2:   also declared as `int A::i' here

The logic of this escapes me, and I am wondering if this is really
the behaviour that the Standard is intending.  Can someone shine a light
on this for me please?

-- 
Carlo Wood <carlo@alinoe.com>                        -=- Jesus Loves you -=-


More information about the Gcc mailing list