I have a problem which involes nested namespaces and templated classes. I was also able to create test case which produces the same error as the actual code, but is a bit more readable.
Compiling the following code using VS2012 with the 2010 platform toolset causes an error:
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();
}
The specific error is as follows:
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 ==========
I do not understand why the symbol 'SMeasResult' would be ambigous to the compiler, as it is used in a separate namespace. What I could find out so far, is that this problem only appears when the classes are templated classes. The same problem does not appear when the template definition is removed.
Can anybody tell me if I did something wrong?
This actually looks like a compiler bug to me. When you consider that the C1Test
version of the function compiled without ambiguity, I suspect that somehow the using namespace within namespace C1Test
is lingering on even into the C2Test
namespace.
This is further corroborated by the fact that g++ 4.4 and 4.5 can both compile this code fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With