[英]I don't understand the error shown by the VS2013 compiler
以下是我尝试使用Visual Studio 2013编译的类。该代码最初是在Visual Studio 2005中编写的。它是来自github的项目 。 显然,该代码可以在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;
};
显示的错误是:
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
谁能告诉我该错误是什么意思???
这意味着在其他地方已经存在一个称为Quaternion
的非模板类(在这种情况下,它在transform.h文件中看起来像)。 如果这是项目中包含的文件之一,则可能是语言规范不再允许的类的前向声明。 您必须自己编辑标题才能解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.