【问题标题】:"too few template-parameter-lists" error reported at template specialization site模板专业化站点报告“模板参数列表太少”错误
【发布时间】:2013-11-21 23:08:47
【问题描述】:

代码中某处有错误,但我不知道如何解决。它说“模板参数列表太少”。我不明白哪个是错误的。

代码如下:

#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

我需要改变什么?

【问题讨论】:

    标签: c++ list templates parameters


    【解决方案1】:

    您应该在此处使用template&lt;&gt; 进行模板特化。

    template<> double Vector3::dot(const ME &o) const 
    

    template<> Vector3::Vector(double x, double y, double z) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多