Jul 20, 2012 at 7:02am UTC
The calls to reserve are fine, but everything else is wrong.
What on earth is the following line supposed to mean?
mValues <vector<vector<float > >;
Instead of
mValues.push_back(std::vector<float >);
it has to be:
mValues.push_back(std::vector<float >());
mValues[i][j].push_back(new std::vector<float >);
makes no sense whatsoever. Correct:
mValues[i].push_back(0.0f);
You can save yourself all this trouble and write the following:
1 2 3 4
Matrix::Matrix(const unsigned int rows, const unsigned int columns) :
mRows(rows), mColumns(columns), mValues(rows,std::vector<float >(columns))
{
}
Last edited on Jul 20, 2012 at 7:03am UTC
Jul 20, 2012 at 7:38am UTC
Well, it means, that every place in a vector has its own vector as an element. To create a Matrix, you need to have 2 dimensional array (or like in my example - vector). Your answer is correct for only one vector, but I want to have a vector of vectors - like array of arrays, but more dynamic).
Jul 20, 2012 at 7:58am UTC
No. mValues(rows,std::vector<float >(columns))
initializes a vector of vectors of float.
Jul 20, 2012 at 3:28pm UTC
You're right, absolutely right, i gave me quite a fresh look on a subject. Thank you.