help with c++ namespace visibility rules problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I've got the following small test case which fails to compile with g++
(g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-9)) - it also fails on other
platforms the same way:

/* -------------------------- t.C ----------------------- */
namespace n1 {
  class C {};
  void f(C& c) {}
}

namespace n2 {
  using n1::C;
  void f(C& c) {}
}

using namespace n2;

void foo(C& c)
{
  f(c);
}
/* ------------------------------------------------------- */

The error is:
t.C: In function `void foo(n1::C&)':
t.C:15: error: call of overloaded `f(n1::C&)' is ambiguous
t.C:8: note: candidates are: void n2::f(n1::C&)
t.C:3: note:                 void n1::f(n1::C&)

Why won't it automatically use n2::f() in this case?  What makes this
ambiguous?  Should the n1 namespace be hidden unless I'm "using" it?

Thanks,
David Mansfield



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux