函数模板返回不完整的值

Function template returns incomplete values

本文关键字:返回 函数模板      更新时间:2023-10-16

此代码可能有什么问题?

template< typename Tp, const uInt N>
Matrix<Tp,N-1,N-1> minorMatrix_IJ(const Matrix<Tp, N, N>& A, uInt Ith_row, uInt Jth_col)
{
    assert(N > 1);
    Matrix<Tp, N-1,N-1> temp;
    uInt k = 0, m = 0;
    for(uInt i = 0; i < N; i++, k++)
    {
        if(i == Ith_row)
        { 
                if(k > 0) k--;
                continue;
        }
        for(uInt j = 0; j < N; j++, m++)
        {
            if(j == Jth_col)
            { 
                if(m > 0) m--;
                continue;
            }
            temp[k][m] = A[i][j];
            std::cout <<"temp: " << temp[k][m] <<"n";
        }
    }
    return temp;
}

在函数内部,temp的值被正确分配,但返回的值在某种程度上得到了错误的值。(矩阵只是一个带有2d数组[rows][cols]的模板类)感谢

我怀疑您的Matrix类行为不正确。也许是复制构造函数。