Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1007275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:35:37+00:00 2026-05-16T08:35:37+00:00

Basically, I have a matrix class like this (with a lot of operator overloads

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:35:38+00:00Added an answer on May 16, 2026 at 8:35 am

    Matrix::minor(0, j) returns a matrix of size (N-1, N-1).
    Calling for its determinant makes the process recursive, which means you are generating a minor (and determinant method) for all p integers, starting from N down to … -infinity ?

    Have you added a specialization for the case where N==1 or N==0 ?
    You have to make sure recursion stops !

    Try adding something like :

    template<>
    struct Matrix<1,1>
    {
      float values[1][1];
    
      float determinant(){ return values[0][0]; }
    };
    

    EDIT :
    Recursion has to be stopped at compile time. Adding an if statement inside the method does not prevent the compiler from compiling all possible paths.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have a small template that looks like: <xsl:template name=templt> <xsl:param name=filter />
I basically have this markup coming from my JSP. I add class in each
I would like to do the following. Basically have a stored procedure call another
Basically I have the following class: class StateMachine { ... StateMethod stateA(); StateMethod stateB();
Basically you have two ways for doing this: for (int x = 0; x
I am writing matrix classes. Take a look at this definition: template <typename T,
Basically I have been trying to forge an understanding of matrix maths over the
Okay, so basically lets say i have a matrix: matrix([[0, 1, 2, 3, 4],
I basically have the following class: .sf-sub-indicator { background: url(/abcprod/images/arrows-ffffff.png) no-repeat -10px -100px; }
I basically have a square image depicting a diagram and what I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.