我有从/扩展矩阵基类(模板类)派生的Matrix4类。模板类的方法在同一个头文件中声明和定义。矩阵类:错误:''''令牌之前的预期主表达式
我只复制了给出错误的“Matrix4”类的部分。行10 &上发生同样的错误13.我看不到任何缺少的变量或参数。我试图带走括号,但无济于事。
我已经搜索了一些关于我可能做错了什么的线索,但是我没有在这个网站的类似问题上找到任何有用的信息......我真的很感谢这个帮助。
的Matrix4类给出错误:
template<typename T>
class Matrix4 : public Matrix<T, 4>
{
public:
Matrix4() { }
inline Matrix4 InitOrthographic(T left, T right, T bottom, T top, T near, T far)
{
const T width = (right - left);
const T height = (top - bottom);
const T depth = (far - near); //error occurs here
(*this)[0][0] = T(2)/width; (*this)[1][0] = T(0); (*this)[2][0] = T(0); (*this)[3][0] = -(right + left)/width;
(*this)[0][1] = T(0); (*this)[1][1] = T(2)/height; (*this)[2][1] = T(0); (*this)[3][1] = -(top + bottom)/height;
(*this)[0][2] = T(0); (*this)[1][2] = T(0); (*this)[2][2] = T(-2)/depth; (*this)[3][2] = -(far + near)/depth; //and here
(*this)[0][3] = T(0); (*this)[1][3] = T(0); (*this)[2][3] = T(0); (*this)[3][3] = T(1);
return *this;
}
基本基质类:
template<typename T, unsigned int D>
class Matrix
{
public:
Matrix() { }
virtual ~Matrix() { }
Matrix(const Matrix& other) { *this = other; }
inline Matrix InitIdentity(); //defined in the same header, but left out here to save space
inline Matrix InitTranslation(const Vector<T, D-1>& r);
inline Matrix& operator=(const Matrix& rhs);
inline Matrix operator*(const Matrix<T,D>& r) const;
inline const T* operator[](int index) const { return m[index]; }
inline T* operator[](int index) { return m[index]; }
private:
T m[D][D];
};
有在底部没有错误“黑客帝国”级,仅在派生“Matrix4”级。
如果因为我下一个YouTube教程的xD
有一个在上面的代码中没有行号。所以10和13是没有意义的。哪一行导致错误?我没有任何错误... – knightrider
此代码充满了在类方法中返回'Matrix'的错误示例。 – Mykola
我添加了注释以指示发生错误的位置。例如_const T depth =(far-near); _ line和_(* this)[0] [3] = T(0); (* this)[1] [3] = T(0); (* this)[2] [3] = T(0); (* this)[3] [3] = T(1); //和here_ – searchnot