Previously, I've been creating 2D arrays of class Object
using the pointer, in the following syntax:
Object** myArray = new Object*[row_num];
for (int i = 0; i < row_num; i++)
{
myArray[i] = new Object[col_num];
[skip]
}
However, many people have been recommending me to use vector<vector<Object>>
rather than using Object**
.
As far as I'm concerned, vector requires more memories as a trade-off for easier change in the array size. However, since the 2D array that I need is used for a backtracking algorithm of a grid (which would never change its dimension once it's determined), I do not feel the necessity of changing them.
Are there any other advantages of vector
that I'm unaware of?