Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我不知道';无法理解VS2013编译器显示的错误_C++_Templates_Migration - Fatal编程技术网

C++ 我不知道';无法理解VS2013编译器显示的错误

C++ 我不知道';无法理解VS2013编译器显示的错误,c++,templates,migration,C++,Templates,Migration,下面是我试图使用Visual Studio 2013编译的类。该代码最初是在VisualStudio2005中编写的。这是一个好主意。显然,该代码将在Visual Studio 2005中编译,但在Visual Studio 2013中会出现语法错误。语言规范有变化吗?或者这是向后兼容性的问题 template<class Real = double> class Quaternion //normalized quaternion for representing rotation

下面是我试图使用Visual Studio 2013编译的类。该代码最初是在VisualStudio2005中编写的。这是一个好主意。显然,该代码将在Visual Studio 2005中编译,但在Visual Studio 2013中会出现语法错误。语言规范有变化吗?或者这是向后兼容性的问题

template<class Real = double>
class Quaternion //normalized quaternion for representing rotations
{
public:
    //constructors
    Quaternion() : r(1.) { } //initialize to identity
    Quaternion(const Quaternion &q) : r(q.r), v(q.v) {} //copy constructor
    template<class R> Quaternion(const Quaternion<R> &q) : r(q.r), v(q.v) {} //convert quaternions of other types
    //axis angle constructor:
    template<class R> Quaternion(const Vector<R, 3> &axis, const R &angle) : r(cos(angle * Real(0.5))), v(sin(angle * Real(0.5)) * axis.normalize()) {}
    //minimum rotation constructor:
    template<class R> Quaternion(const Vector<R, 3> &from, const Vector<R, 3> &to) : r(1.)
    {
        R fromLenSq = from.lengthsq(), toLenSq = to.lengthsq();
        if(fromLenSq < toLenSq) {
            if(fromLenSq < R(1e-16))
                return;
            Vector<R, 3> mid = from * sqrt(toLenSq / fromLenSq) + to;
            R fac = 1. / sqrt(mid.lengthsq() * toLenSq);
            r = (mid * to) * fac;
            v = (mid % to) * fac;
        }
        else {
            if(toLenSq < R(1e-16))
                return;
            Vector<R, 3> mid = from + to * sqrt(fromLenSq / toLenSq);
            R fac = 1. / sqrt(mid.lengthsq() * fromLenSq);
            r = (from * mid) * fac;
            v = (from % mid) * fac;
        }
    }

    //quaternion multiplication
    Quaternion operator*(const Quaternion &q) const { return Quaternion(r * q.r - v * q.v, r * q.v + q.r * v + v % q.v); }

    //transforming a vector
    Vector<Real, 3> operator*(const Vector<Real, 3> &p) const
    {
        Vector<Real, 3> v2 = v + v;
        Vector<Real, 3> vsq2 = v.apply(multiplies<Real>(), v2);
        Vector<Real, 3> rv2 = r * v2;
        Vector<Real, 3> vv2(v[1] * v2[2], v[0] * v2[2], v[0] * v2[1]);
        return Vector<Real, 3>(p[0] * (Real(1.) - vsq2[1] - vsq2[2]) + p[1] * (vv2[2] - rv2[2]) + p[2] * (vv2[1] + rv2[1]),
                               p[1] * (Real(1.) - vsq2[2] - vsq2[0]) + p[2] * (vv2[0] - rv2[0]) + p[0] * (vv2[2] + rv2[2]),
                               p[2] * (Real(1.) - vsq2[0] - vsq2[1]) + p[0] * (vv2[1] - rv2[1]) + p[1] * (vv2[0] + rv2[0]));
    }

    //equality
    template<class R> bool operator==(const Quaternion<R> &oth) const
    {
        return (r == oth.r && v == oth.v) || (r == -oth.r && v == -oth.v);
    }

    Quaternion inverse() const { return Quaternion(-r, v); }

    Real getAngle() const { return Real(2.) * atan2(v.length(), r); }
    Vector<Real, 3> getAxis() const { return v.normalize(); }

    const Real &operator[](int i) const { return (i == 0) ? r : v[i - 1]; }
    void set(const Real &inR, const Vector<Real, 3> &inV) {
        Real ratio = Real(1.) / sqrt(inR * inR + inV.lengthsq()); 
        r = inR * ratio; v = inV * ratio; //normalize
    }

private:
    Quaternion(const Real &inR, const Vector<Real, 3> &inV) : r(inR), v(inV) {}

    Real r;
    Vector<Real, 3> v;
};

有人能告诉我这个错误是什么意思吗?

这意味着在其他地方已经有一个名为
Quaternion
的非模板类(在本例中,它类似于transform.h文件)。如果这是项目中包含的文件之一,那么它可能是语言规范不再允许的类的转发声明。您必须自己编辑标题才能解决问题。

这意味着在其他地方已经有一个名为
四元数的非模板类(在本例中,它类似于transform.h文件)。如果这是项目中包含的文件之一,那么它可能是语言规范不再允许的类的转发声明。您必须自己编辑标题才能解决问题。

上面的代码本身来自transform.h文件,很抱歉我之前没有提到它,上面的代码本身来自transform.h文件,很抱歉,在您的项目中搜索四元数的正向定义之前,我没有提到它,您没有将其指定为模板。非常感谢。。。我得到了它。。。我链接了另一个项目,其中又有一个四元数的定义…在您的项目中查找
四元数的正向定义,您没有将其指定为模板。非常感谢。。。我得到了它。。。我有另一个项目,再次有一个四元数的定义。。。
Error   1   error C2989: 'Quaternion' : class template has already been declared as a non-class template    c:\users\student\documents\visual studio 2013\projects\narovatar\imp_pinocchio\transform.h  93  1   Rigging

Error   3   error C3857: 'Quaternion': multiple template parameter lists are not allowed    c:\users\student\documents\visual studio 2013\projects\narovatar\imp_pinocchio\transform.h  24  1   Rigging