⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allocate2darray.cpp

📁 单用户dscdma的仿真
💻 CPP
字号:
//#include"Allocate2DArray.cpp"
// --------------------------------------------------------------------------
// 动态分配二维数组
// 使用方法(以int类型8行10列为例): int **dyarr = Allocate2DArray<int>(8,10)
//template<double>
double **Allocate2DArray(size_t pm_Rows, size_t pm_Cols)
{
    double **arr = new double*[pm_Rows];
    for (int i = 0; i < pm_Rows; i++)
        arr[i] = new double[pm_Cols];
    return arr;
}

// --------------------------------------------------------------------------
// 释放动态分配的二维数组
// 使用方法(以int类型8行10列为例): Allocate2DArray<int>(dyarr,8)
//template<double>
void DeAllocate2DArray(double **arr, size_t pm_Rows)
{
    for (int i = 0; i < pm_Rows; i++)
        delete[] arr[i];
    delete[] arr;
}
int **intAllocate2DArray(size_t pm_Rows, size_t pm_Cols)
{
    int **arr = new int*[pm_Rows];
    for (int i = 0; i < pm_Rows; i++)
        arr[i] = new int[pm_Cols];
    return arr;
}

// --------------------------------------------------------------------------
// 释放动态分配的二维数组
// 使用方法(以int类型8行10列为例): Allocate2DArray<int>(dyarr,8)
//template<double>
void intDeAllocate2DArray(int **arr, size_t pm_Rows)
{
    for (int i = 0; i < pm_Rows; i++)
        delete[] arr[i];
    delete[] arr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -