unique_ptr<int> ptr1(new int {});
unique_ptr<int[]> ptr2(new int[5] {});
single and one-dimensional array can be declared as above. How do I declare a two-dimensional or more array as a smart pointer?
const size_t idx = 5;
// 2D
int** ptr3 = new int*[idx]{};
for (size_t i = 0; i < idx; i++)
{
ptr3[i] = new int[idx]{};
}
for (size_t i = 0; i < idx; i++)
{
delete[] ptr3[i];
}
delete[] ptr3;
// 3D
int*** ptr4 = new int**[idx]{};
for (size_t i = 0; i < idx; i++)
{
ptr4[i] = new int*[idx]{};
for (size_t j = 0; j < idx; j++)
{
ptr4[i][j] = new int[idx]{};
}
}
... skip ...
-----> smart pointer version?