template recursion when I use the non-type parameter

  c++, templates
template<typename T, int row, int column>
T determinant(const Mat<T, row, column>& current)
{
    if (row == 1) return current[0][0];
    if (row == 2) return current[0][0] * current[1][1] - current[0][1] * current[1][0];
    T sum = 0;
    for (int i = 0; i <= row - 1; i++)
    {
        T sign = 1;
        if (i % 2 == 1) sign = -sign;
        Mat<T, row +1, column + 1> next;
        for (int j = 0, nextRow = 0; j <= row - 1; j++)
        {
            if (i == j) continue;
            for (int k = 0; k <= row - 2; k++)
            {
                next[nextRow][k] = current[j][k + 1];
            }
            nextRow++;
        }
        sum += sign * current[i][0] * determinant(next);
    }
    return sum;
}

I want to write a Matrix class. But when I want to handle the determinant function, I get into trouble. What is my fault? What should I do?

Source: Windows Questions C++

LEAVE A COMMENT