Vector push_back Array of doubles

user3794592

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.

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 Error: type name is not allowed

I'm using VisualStudio 2012. Can somebody tell me, what I'm doing wrong?

Sean

A std::array is copyable, so if you want to copy the first item to the end just say:

matrix.push_back(matrix[0]);

As for why you're getting the error, it's because you're passing the name of a type to push_back rather than an object.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Insert or push_back to end of a std::vector?

From Dev

string Vector push_back failing in class

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

vector::push_back and std::move

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

How to use vector iterators when using vector<>::push_back()

From Dev

C++ Vector: push_back Objects vs push_back Pointers performance

From Dev

vector push_back zero into an empty vector

From Dev

garbage values for vector push_back

From Dev

Why are there two overloads for vector::push_back?

From Dev

Vector and push_back() behavior

From Dev

push_back new element to vector

From Dev

vector push_back in STL?

From Dev

push_back an array into a matrix c++

From Dev

C++ how to push_back an array int[10] to std::vector<int[10]>?

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

vector push_back causes assertion error but list push_back works

From Dev

c++ vector - what's the difference between push_back(*new obj()) and push_back(obj())?

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

How to use vector iterators when using vector<>::push_back()

From Dev

garbage values for vector push_back

From Dev

Vector push_back incredibly slow

From Dev

Unable to push_back to vector

From Dev

push_back a vector of vectors into a vector

From Dev

C++ how to push_back an array int[10] to std::vector<int[10]>?

From Dev

Push_back variadic function parameters into a vector?

From Dev

c++ push_back() a struct into a vector

From Dev

vector of reference wrapper, push_back failure?

From Dev

push_back a pointer to a vector of pointers

Related Related

HotTag

Archive