There is an error somewhere in the code, but I don't know how to solve. It says "too few template-parameter-lists". I don't understand which is the mistake.
Here is the code:
#if !defined(VECTOR_H_INCLUDED)
#define VECTOR_H_INCLUDED
#include <cstdlib> // for size_t
namespace Vec
{
class Vector_base
{
public:
explicit Vector_base() {}
};
template<typename T, int DIM>
class Vector : public Vector_base
{
typedef Vector<T,DIM> ME;
explicit Vector(T,T,T);
double dot(const ME &v) const;
T &operator [](size_t n)
{
return v[n];
}
T operator [](size_t n) const
{
return v[n];
}
private:
T v[DIM];
};
typedef Vector<double,3> Vector3;
double Vector3::dot(const ME &o) const // ----- it gives me the error here ...
{
return v[0] * o[0] + v[1] * o[1] + v[2] * o[2];
}
Vector3::Vector(double x, double y, double z) // ----- ... and here
{
v[0] = x;
v[1] = y;
v[2] = z;
}
}
#endif // VECTOR_H_INCLUDED
What do I have to change?
You should use template<>
here to make template specializations.
template<> double Vector3::dot(const ME &o) const
and
template<> Vector3::Vector(double x, double y, double z)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With