So far good, but where are you allocating the object, that is only thing missing.
Here is a generic example
template <typename T>
T *** New2DArray(int rows, int cols)
{
T *** array = new T**[rows];
for(int r = 0; r < rows; ++r)
{
array[r] = new T*[cols];
for(int c = 0; c < cols; ++c)
array[r][c] = new T;
}
return array;
}
template <typename T>
void Delete2DArray(T *** array, int rows, int cols)
{
for(int r = 0; r < rows; ++r)
{
for(int c = 0; c < cols; ++c)
delete array[r][c];
delete[] array[r];
}
delete[] array;
}
...
...
Delete2DArray(array, rows, cols);
...
template <typename T>
T *** New2DArray(int rows, int cols)
{
T *** array = new T**[rows];
for(int r = 0; r < rows; ++r)
{
array[r] = new T*[cols];
for(int c = 0; c < cols; ++c)
array[r][c] = new T;
}
return array;
}
template <typename T>
void Delete2DArray(T *** array, int rows, int cols)
{
for(int r = 0; r < rows; ++r)
{
for(int c = 0; c < cols; ++c)
delete array[r][c];
delete[] array[r];
}
delete[] array;
}
...
QGraphicsRectItem *** objRect = New2DArray<QGraphicsRectItem>(rows, cols);
...
Delete2DArray(array, rows, cols);
...
To copy to clipboard, switch view to plain text mode
Bookmarks