This does this without having to mention A again:
array<std::vector<A>, 3> v{{ {1}, {2,3,4}, {} }};
if the constructor takes two arguments, you must write them in braces:
array<std::vector<A2>, 3> v2{{ {{1,2}}, {{2,3},{4,5},{8,9}}, {} }};
I would prefer the following syntax, which also works if the constructor is explicit.
std::array<std::vector<A2>, 3> v2{{ {A2{1,2}}, {A2{2,3},A2{4,5},A2{8,9}}, {} }};
Full example:
#include <array> #include <vector> #include <iostream> struct A2 { A2(int k,int j) : mk(k),mj(j) {} int mk; int mj; }; int main (){ std::array<std::vector<A2>, 3> v2{{ {{1,2}}, {{2,3},{4,5},{8,9}}, {} }}; int i=0; for (auto &a : v2){ std::cout << "... " << i++ <<std::endl; for (auto &b : a){ std::cout << b.mk << " " <<b.mj <<std::endl; } } }