How to resize 3D vector in C++ with custom type?

Viewed 73

I have this so far:

int x; 
int rows;
int colm;

vector<vector<vector<Piece>>> Map;

map.resize(x, vector<Piece>(rows, colm);

this is trying to create a vector that contains x amount of 2d vectors of pieces where 2d vector is resized by rows.

1 Answers

Didn't test but something like this should work.

void resize_3d(v3d_t x, int x_size, int row_size, int col_size) {
  x.resize(x_size);
  for (auto& row : x) {
    row.resize(row_size);
    for (auto& col : row) {
      col.resize(col_size);
    }
  }
}
Related