Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"too few template-parameter-lists" error reported at template specialization site

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?

like image 476
Ale Avatar asked Nov 09 '13 23:11

Ale


1 Answers

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) 
like image 163
Phillip Kinkade Avatar answered Nov 05 '22 19:11

Phillip Kinkade