Jump to content
  • Advertisement
Sign in to follow this  
Amma

C++ Template partial specialization problems

This topic is 5413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Simple. Partial template specialisation dun't work in VS.NET 2002 - dun't know if they fixed that in 2003.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!