我有以下一组类(对我的真实情况的最小复制):
namespace Parent
{
class A {};
namespace Nested
{
class A {};
}
template <typename T>
class B
{
A myA;
};
}
我希望该成员Parent::B::myA
应该被明确地解析为 type Parent::A
。但是,在我的项目的其他地方,我有这个:
namespace Parent
{
using namespace Nested;
void foo()
{
B<int> myB;
}
}
在 MSVC 2003 下编译失败:
error C2872: 'A' : ambiguous symbol
could be 'Test.cpp(5) : Parent::A'
or 'Test.cpp(9) : Parent::Nested::A'
Test.cpp(26) : see reference to class template instantiation 'Parent::B<T>' being compiled
with [ T=int ]
如果我在声明中明确说明,代码将编译B::myA
,即Parent::A myA;
。但是,代码在gcc-4.3.4下编译。这仅仅是 MSVC 2003 的一个错误,还是我真的应该担心我的模板可能被实例化的范围?