C++ Template partial specialization problems

Started by
2 comments, last by Polymorphic OOP 19 years, 6 months ago
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?
-----------------------------Amma
Advertisement
Simple. Partial template specialisation dun't work in VS.NET 2002 - dun't know if they fixed that in 2003.
-- Single player is masturbation.
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.
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