C++ Template partial specialization problems
Can someone tell why this doesn't compile in VC++ 2003?
struct CBase {
int m_Value1;
};
template <int __T>
struct CTemplate : public CBase {
int m_Value2;
};
template <>
struct CTemplate<1234> {
int m_Value3;
};
void Test()
{
CTemplate<1230> test1;
CTemplate<1234> test2;
test1.m_Value1;
test1.m_Value2;
test2.m_Value1; <--- Error
test2.m_Value2; <--- Error
test2.m_Value3;
}
No inheriage from specialized templates?? Is this actually C++ standard?
Simple. Partial template specialisation dun't work in VS.NET 2002 - dun't know if they fixed that in 2003.
Partial template specialization works fine in VC++ 2003. Besides, you're not doing partial specialization here, you're doing full specialization.
According to your code, test2 will be a structure with m_Value3 only because CTemplate<1234> has no base. As far as I see, the compiler works fine.
According to your code, test2 will be a structure with m_Value3 only because CTemplate<1234> has no base. As far as I see, the compiler works fine.
Again, what you are doing is explicit specialization, not partial. Your code doesn't compile because you didn't inherit from CBase nor declare m_Value2 in your specialization, therefore they don't exist in your second object. .NET 2003 works perfectly fine with explicit and partial specialization.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement