嵌套的命名空间和模糊的符号

Sim*_*mon 7 c++ templates namespaces using visual-studio-2010

我有一个问题,它会侵入嵌套的命名空间和模板化的类.我还能够创建测试用例,它产生与实际代码相同的错误,但更具可读性.

使用VS2012和2010平台工具集编译以下代码会导致错误:

namespace A
{
   namespace B
   {
      namespace C1
      {
         struct SMeasResult{};
      }
      namespace C2
      {
         struct SMeasResult{};
      }
   }
}

namespace C1Test
{
   using namespace A::B::C1;

   template<typename T>
   class Fook
   {
   public:

      void Yu()
      {
         SMeasResult Field;
      }
   };
}

namespace C2Test
{
   using namespace A::B::C2;

   template<typename T>
   class Fook
   {
   public:

      void Yu()
      {
         SMeasResult Field;
      }
   };
}

void m(){
   C1Test::Fook<int> yu;
   C2Test::Fook<int> me;

   yu.Yu();
   me.Yu();
}
Run Code Online (Sandbox Code Playgroud)

具体错误如下:

1>------ Build started: Project: MultiVicomTest (Visual Studio 2010), Configuration: Debug Win32 ------
1>  test.cpp
1>c:\code\test.cpp(27): warning C4101: 'Field' : unreferenced local variable
1>          c:\code\test.cpp(26) : while compiling class template member function 'void C1Test::Fook<T>::Yu(void)'
1>          with
1>          [
1>              T=int
1>          ]
1>          c:\code\test.cpp(49) : see reference to class template instantiation 'C1Test::Fook<T>' being compiled
1>          with
1>          [
1>              T=int
1>          ]
1>c:\code\test.cpp(43): error C2872: 'SMeasResult' : ambiguous symbol
1>          could be 'c:\code\test.cpp(11) : A::B::C2::SMeasResult'
1>          or       'c:\code\test.cpp(7) : A::B::C1::SMeasResult'
1>          c:\code\test.cpp(42) : while compiling class template member function 'void C2Test::Fook<T>::Yu(void)'
1>          with
1>          [
1>              T=int
1>          ]
1>          c:\code\test.cpp(50) : see reference to class template instantiation 'C2Test::Fook<T>' being compiled
1>          with
1>          [
1>              T=int
1>          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)

我不明白为什么符号'SMeasResult'对编译器来说是不明显的,因为它在一个单独的命名空间中使用.到目前为止我能找到的是,只有在类是模板化类时才会出现此问题.删除模板定义时不会出现相同的问题.

任何人都可以告诉我,如果我做错了什么?

Mar*_*k B 3

对我来说,这实际上看起来像是一个编译器错误。当您考虑到C1Test编译的函数版本没有歧义时,我怀疑其中的 using 命名空间以某种方式namespace C1Test甚至在命名空间中徘徊C2Test

g++ 4.4 和 4.5 都可以很好地编译此代码,这一事实进一步证实了这一点。