Vector Push_back of Array

So I got a vector of multidimensional arrays of doubles.
The vector is created with this code
 
std::vector<std::array<double, 3>> matrix;

After this the vector is filled with the xy coordinates of points and other informations, and sorted. This is needed so I become the outer shape of a given 2d model. To close the outer shape of the model, I have to copy the informations of the first point to the end of the vector.
I know, if I have a vector of vectors I could use code like this.
1
2
3
4
5
matrix.push_back(std::vector<double>(3, 0));
int p = matrix.size()-1;		
matrix[p][0]=matrix[0][0];
matrix[p][1]=matrix[0][1];
matrix[p][2]=matrix[0][2];

Since I'm using a vector of arrays, this seems to be wrong. I tried to use this code slightly modified.
 
matrix.push_back(std::array<double, 3>);

But here I get the error message:
class: std::array<double, 3U> Error: type name is not allowed

I'm using VisualStudio 2012. Can somebody tell me, what I'm doing wrong?
Last edited on
The problem is that you have only passed a type. To create a temporary object you need to put parentheses after the type.

 
matrix.push_back(std::array<double, 3>());


Note that you don't need to copy each element in the array, one by one, but instead you can copy the whole array, all at once.

 
matrix[p] = matrix[0];


But the simplest way to do what you want is probably to just pass the first array to push_back directly.

 
matrix.push_back(matrix[0]);
Last edited on
Thanks it worked fine.
Topic archived. No new replies allowed.