Skip to main content
gamedev.net
🔒 Locked

Template Problem

Started by Gammastrahler 4 replies 350+ views
Original Post
Gammastrahler
Gammastrahler
Hi, i have typed this code example from the book C++ templates, chapter 17, template meta programming.
    
template <int DIM, typename T>
class DotProduct 
{
	public:
		static T result(T* a, T* b)
		{
			return *a * *b + DotProduct<DIM - 1, T>::result(a + 1, b + 1);
		}
};

template <typename T>
class DotProduct<1, T>
{
	static T result(T* a, T* b)
	{
		return DotProduct<DIM, T>::result(a, b);
	}
};
    
i got two compiler errors in MSVC++ 6.0, C2989 (template class has already been defined as a non-template class) and C2988 (unrecognizable template declaration/definition). Do i need a newer compiler?? I would be glad to get any help! Thanks Gammastrahler [edited by - Gammastrahler on March 10, 2003 4:57:41 PM]
Null and Void
Null and Void
Your code is fine (I checked it in gcc version 3.2.3 20030228 (Debian prerelease)).

Matsen
Matsen
VC6 doesn''t support class template partial specialization

Read more here

Regards Mats

(didn''t compile under gcc 3.1: `DIM'' undeclared)
Gammastrahler
Gammastrahler
Thanks for the quick answers!

Can someone tell me which compilers support partial specializations? Is VC++ .NET supporting this? And what´s up with the other template features like template template parameters?

thanks
Gammastrahler
Shannon Barber
Shannon Barber
The current released version of MSVC7 does not support partial template specialization. v7.1 is suppose to.
7.0 supports non-ordinal template-template parameters.

For the PC: gcc 3.2 (most stuff works on 2.95.3), CodeWarrior6 (about 90%), C++ Builder 5.5, Intel 6.0 (a few things work on 5.0), and Comeau

For other platforms, I''m not certain.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Matsen
Matsen
What are non-ordinal template-template parameters? Google gave me nothing.

Regards Mats

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.