I have the following class definitions:
template<unsigned dim>
class Vector
{ ... };
template<unsigned dim>
class Displacement : public Vector<dim>
{ ... };
template<unsigned dim>
class Velocity : public Vector<dim>
{ ... };
template<unsigned dim>
class Acceleration : public Vector<dim>
{ ... };
etc.
Now I want to overload binary operators +, - , *, /. But I don't want to write member functions for all vector types. (there are too many.) So I wrote the following template function:
template<typename T, unsigned dim>
T<dim> operator + (const T<dim> & t0, const T<dim> & t1) <<<< C2988 on this line
{
T<dim> ret;
for (int i=0; i<dim; i++)
ret[i] = t0[i] + t1[i];
}
But I get compiler error C2988 (unrecognizable template declaration/definition; Visual Studio Pro 2008). The help page (
http://msdn.microsoft.com/en-us/library/f69a8fb8.aspx) is pretty useless.
Is it possible to write template like above (of course, w/o syntax errors) or do I have no choice but to copy-paste for all types derived from Vector<dim>?
Start Free Trial