小编Cag*_*Alp的帖子

在函数中分配内存并返回它

int** transpose(int** matrix,int row, int column)
{
    int** new_mat = new int*[column];


    for(int i = 0; i < column; i++)
    {
        new_mat[i] = new int[row];
    }
    for(int i  = 0; i < row; i++ )
    {
        for(int j = 0; j < column; j ++)
        {
            new_mat[j][i] = matrix[i][j];
        }
    }

    return new_mat;
}
Run Code Online (Sandbox Code Playgroud)

我已经编写了这个函数但是感觉不对我无法决定是否应该删除new_mat,基本上函数返回这个值我应该如何处理内存而不使用任何智能指针或什么?

c++ memory-management

5
推荐指数
1
解决办法
141
查看次数

标签 统计

c++ ×1

memory-management ×1