From the std::vector
reference page:
Vectors can be constructed with some values in them.
You may try:
vector<vector<Distance*> > distanceMatrix(7, vector<Distance*>(7, NULL));
Also, regarding your problem:
vector<vector<Distance*> > distanceMatrix;
for (int i = 0; i < 7 ; i++)
for (int j = 0; j < 7 ; j++)
distanceMatrix[i][j].push_back(NULL); //1
When you code first reach //1
, distanceMatrix[i]
resolves to distanceMatrix[0]
but you did not call distanceMatrix.push_back(vector<Distance*>())
so you are referring to a non initialized cell.
To correct code would have been:
vector<Distance*> vec;
for (int j = 0; j < 7 ; j++)
vec.push_back(NULL);
vector<vector<Distance*> > distanceMatrix;
for (int i = 0; i < 7 ; i++)
{
distanceMatrix.push_back(vec);
}
Which is still far worse than my first suggestion.