函数模板返回不完整的值
Function template returns incomplete values
此代码可能有什么问题?
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类行为不正确。也许是复制构造函数。
相关文章:
- 函数模板返回类型
- 在实例化之前推断函数模板的返回类型
- 使用函数模板推导返回类型
- 为什么用户定义的转换函数模板不能有推导的返回类型?
- 使用函数模板返回类型 X 的变量的值
- 是否可以将变量/函数返回作为模板参数传递
- 如何声明接受转发引用并返回引用或副本的函数模板
- 按返回类型重载函数模板
- 返回函数模板的类型C++作为第二个模板参数
- 如何根据"function like"参数推导函数模板的返回类型?
- 函数模板中的无效转换错误,返回值取决于其泛型类型
- 从返回函数中推断不存在的模板参数
- C++函数模板:必须使用 & for 参数类型和返回类型?
- 如何在返回类型函数模板的专用化中使用派生类型?( "couldn't infer template argument" )
- <func-param> 函数模板中的is_const始终返回 false
- 使用decltype尾部返回类型专门化函数模板
- 为什么从 void 函数模板返回时没有收到编译器错误?
- 与模板返回函数的返回错误
- 函数模板 - 基于输入类返回 T?-C++
- 具有返回类型的函数模板,该返回类型不能从参数中推导出来