Basically, I have a matrix class like this (with a lot of operator overloads and other functions removed):
template
<
uint32 TRows,
uint32 TCols
>
struct Matrix
{
float values[TRows][TCols];
inline explicit Matrix()
{
}
inline Matrix<TRows - 1, TCols - 1> minor(const uint32 col, const uint32 row)
{
Matrix<TRows - 1, TCols - 1> matrix;
for(int i = 0; i < TRows; ++i)
for(int j = 0; j < TCols; ++j)
{
if(i == col || j == row) continue;
matrix.values[i - (i > col)][j - (j > row)] = this->values[i][j];
}
return matrix;
}
inline float determinant()
{
if(TRows != TCols) throw DimensionError("Matrix is not square");
float det = 0;
if(TRows <= 0)
det = 0;
else if(TRows == 1)
det = this->values[0][0];
else if(TRows == 2)
det = this->values[0][0] * this->values[1][1] - this->values[1][0] * this->values[0][1];
else
for(int j = 0; j < TCols; ++j)
det += (j % 2 ? -1 : 1) * this->values[0][j] * this->minor(0, j).determinant();
return det;
}
}
I don't understand why, for the line det += (j % 2 ? -1 : 1) * this->values[0][j] * this->minor(0, j).determinant();
, GCC attempts to generate an immense amount of functions:
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -49u, unsigned int TCols = -49u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -48u, unsigned int TCols = -48u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -47u, unsigned int TCols = -47u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -46u, unsigned int TCols = -46u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -45u, unsigned int TCols = -45u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -44u, unsigned int TCols = -44u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -43u, unsigned int TCols = -43u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -42u, unsigned int TCols = -42u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -41u, unsigned int TCols = -41u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -40u, unsigned int TCols = -40u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -39u, unsigned int TCols = -39u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -38u, unsigned int TCols = -38u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -37u, unsigned int TCols = -37u]'
matrix.cpp:95: instantiated from `float Matrix<TRows, TCols>::determinant() [with unsigned int TRows = -36u, unsigned int TCols = -36u]'
This is probably some error in my code, but I can't for the life of me see where I'm going wrong. Help would be much appreciated!