Matrix class: error: expected primary expression before the character ')'

I have a Matrix4 class derived from / extension of the Matrix base class (template class). Template class methods are declared and defined in the same header file.

I just copied the part of the Matrix4 class that gives the error. The same error occurs on lines 10 and 13. I do not see any missing variables or arguments. I tried to pick up the brackets, but to no avail.

I was looking for the key to what I can do wrong, but I did not find anything useful in such matters on this site ... I would really appreciate help.

Matrix4 class throwing an error:

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;
    }

Base matrix class:

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];
};

There are no errors in the base class "Matrix", only in the derived class "Matrix4".

, Youtube Tutorial xD

+4
2

, MS Visual ++

template<typename T, unsigned int D>
class Matrix
{
    public:
        Matrix() { }
        virtual ~Matrix() { }
        Matrix(const Matrix<T, D>& other) { *this = other; }

        inline Matrix<T, D> InitIdentity();   //defined in the same header, but left out here to save space
        inline Matrix<T, D> InitTranslation(const Vector<T, D-1>& r);
        inline Matrix<T, D>& operator=(const Matrix<T, D>& rhs);
        inline Matrix<T, D> 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];
};

template<typename T>
class Matrix4 : public Matrix<T, 4>
{
public:
    Matrix4() { }

    inline Matrix4<T> 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;

        (*this)[0][3] = T(0);       (*this)[1][3] = T(0);        (*this)[2][3] = T(0);        (*this)[3][3] = T(1);  //and here

        return *this;
    }
};

, Vector, int

+1

! !

"far" "near" _ "m_near" _ _ "m_far" _, . , #define - .

. , /. , , , .

, , , - , .

Matrix4:

inline Matrix4<T> InitOrthographic(T left, T right, T m_near, T m_far, T bottom, T top)
{
    const T width = right - left;
    const T height = top - bottom;
    const T depth = m_far - m_near;  

    (*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] = -(m_far + m_near)/depth;
    (*this)[0][3] = T(0);       (*this)[1][3] = T(0);        (*this)[2][3] = T(0);        (*this)[3][3] = T(1);

    return *this;
}
+2

Source: https://habr.com/ru/post/1612068/


All Articles