Qt 3D-array with Qt-Objekts like QVector

后端 未结 2 1267
悲哀的现实
悲哀的现实 2021-01-24 20:32

How can I create a 3D-array only with Qt-Objects? The array should be a 3D-integer-array. I have tried to create a standard 3D-array on the heap. To allocate the memory on the h

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-24 21:09

    HEAP CORRUPTION occurred because of <=. If you replace <= to <, your code will work.

    const int scalefaktor = 16;
    int*** anzPixel3d = new int**[scalefaktor];
    for (int i = 0; i < scalefaktor ; i++)
    {
        anzPixel3d[i] = new int*[scalefaktor];
        for (int k = 0; k < scalefaktor ; k++)
        {
            anzPixel3d[i][k] = new int[scalefaktor];
        }
    }
    
    for (int j = 0; j < scalefaktor ; j++)
    {
        for (int m = 0; m < scalefaktor ; m++)
        {
            delete [] anzPixel3d[j][m];
        }
        delete [] anzPixel3d[j];
    }
    delete [] anzPixel3d;
    

提交回复
热议问题