I have a vector object:
std::vector<std::vector<MyClass>> _matrix;
It is 2d array with some data.
When i trying to resize the dimensions with:
_matrix.resize(_rows, std::vector<MyReal>(_colms)); //_rows and _colms are ints
this command simply does nothing to the object.
So to resize it i have to call first to:
_matrix.clear();
and then:
_matrix.resize(_rows, std::vector<MyReal>(_colms));
Of course, I’m losing the data. (In my case it doesn’t matter)
Is this expected behaviour?
From the docs for
vector::resize:Only the new rows get vectors with additional columns (
std::vector<MyReal>(_colms)).resizewill not change the existing rows.Update: To resize the entire vector properly, iterate over the existing rows and resize those vectors, then add the new rows. Something like this should work: