c++ - how to initialize an array of std::vector? -
as know, it's normal initialize array of int
this:
int intary[] = {7, 8, 9};
so, want know, how can initialize array of std::vector in same way
(just in initial list):
typedef std::vector<int> type; type vecary[] = {vec1, vec2, vec3};
i know it's legal write code fllows, question how initialize vecary in 1 line of code:
type vec1; type vec2; type vec3; type vecary = {vec1, vec2, vec3};
in c++11,
type vecary[] {{},{},{}};
or if want non-empty vectors
type vecary[] {{1,2,3},{4,5,6},{7,8,9}};
if you're stuck in past, can initialise empty vectors:
type vecary[] = {type(), type(), type()};
but can't initialise arbitrary values without kind of helper in boost assignment library:
type vecary[] = {list_of(1)(2)(3), list_of(4)(5)(6), list_of(7)(8)(9)};
Comments
Post a Comment