list<int> *l;
makes l
a pointer to a list<int>
but it doesn't actually create a list<int>
- and definitely not an array of list<int>
which you are trying to access.
Possible solutions.
Plain C fixed size arrays of list<int>
:
#include <iostream>
#include <list>
int main() {
std::list<int> l[11]; // place for 11 list<int>`'s
l[0].push_back(1);
l[10].push_back(12);
}
Using the C++ fixed sized std::array:
#include <array>
#include <list>
int main() {
std::array<std::list<int>, 11> l; // place for 11 list<int>'s
l[0].push_back(1);
l[10].push_back(12);
}
Using a C++ std::vector
that allows for dynamicially adding more list<int>
's:
#include <list>
#include <vector>
int main() {
std::vector<std::list<int>> l(11); // starts with place for 11 list<int>'s
l[0].push_back(1);
l[10].push_back(12);
}