Templated Vector and Colour Maths library (Specialisation)
<p>I have created a maths library that operates via templates, it allows the user to specify the size and type of the array within a class which is then used to create a maths vector of any dimension up to four. As soon as I went to create a colour class, it struck me how similar the vector and colour class are. Is there anyway in which I could reduce code reuse and use some form of inheritance or specialisation to separate:</p>

<ol>
<li>Specific functionality (ie vector3 does not have a setXYZW() function, instead only a setXYZ()) to the dimension of which it can only be used in.</li>
<li>Colour class and vector class can both (in terms of array data member) be of size ranging from 1 to 4 and the both share the same operators, but differ in their use in some circumstances such as a multiply vector differs from a multiply colour.</li>
</ol>

<p>My knowledge of templates is not that good, so I would very much appreciate if anyone can show me the best solution to such a situation?</p>

<p><pre>
<code>template &lt; std::size_t N = 3, typename T = float >
class Vector
{
  typedef T Degree, Radian;
private:
  T m_vecEntry[N];
public:
  // arithmetic operations
  Vector operator + (const Vector &amp; _vector) const;
  Vector operator - (const Vector &amp; _vector) const;
  Vector operator * (const Vector &amp; _vector) const;
  Vector operator * (float _val) const;
};
</pre></code></p>

<p><pre>
<code>template &lt; std::size_t N = 4, typename T = float >
class Colour
{
private:
  T m_colEntry[N];
public:
  // arithmetic operations
  Colour operator + (const Colour&amp; _colour) const;
  Colour operator - (const Colour&amp; _colour) const;
  Colour operator * (const Colour&amp; _colour) const;
  Colour operator * (float _val) const;
};
</pre></code></p>
