MikkelSecher
MikkelSecher

Reputation: 105

A list<> of integer arrays in C++?

I need a dynamic list of integer arrays.

I would think that it could be declared as:

list<int[10]> myListOfArrays; 

But this doesn't work, and the compiler returns the errors:

error: 'std::_list_node<_Tp>::_M_data' has incomplete type
error: invalid use of array with unspecified bounds

Is there a way to do this?

The size of the integer arrays need not be dynamic, only the number of lists.

Upvotes: 0

Views: 3975

Answers (2)

Jacob
Jacob

Reputation: 164

list<int*> myListOfArrays; will work, particularly as you are happy with the arrays of ints having a static size.

Something like:

std::list<int*> listOfArrays;

int[10] intArray;

listOfArrays.push_back(intArray);

What you are really doing is storing int pointers in your list.

Upvotes: 0

Use a std::list of std::array<int,10>.

Upvotes: 9

Related Questions