Can you have a vector of arrays in C++?

Viewed 138

I want to keep a vector of numbers. I'm not sure what having a vector of arrays looks like, but I'd imagine it looks like this:

std::vector<int[5]> myvector;

And then access it like this:

myvector[3][4] = 3;

Strangely (or not) I've never seen this technique before. Is there a reason for it. Is it just inherently uncommon for such a thing? Or would it be better to wrap the array in a class object type?

1 Answers

In general you can not create a vector of arrays because arrays do not have the assignment operator and the copy constructor.

But you can create a vector of objects of the type std::array<int, 5>

Related