How to initialize an array easily in the constructor? For example
class A
{
array<array<int, 2>, 2> m;
A(int m00, int m01, int m10, int m11)
: m {m00, m01, m10, m11} // ??? how to list here
{}
};
How to initialize an array easily in the constructor? For example
class A
{
array<array<int, 2>, 2> m;
A(int m00, int m01, int m10, int m11)
: m {m00, m01, m10, m11} // ??? how to list here
{}
};
class A
{
std::array<std::array<int, 2>, 2> m;
A(int m00, int m01, int m10, int m11)
: m {{{m00, m01}, {m10, m11}}}
{}
};
{m00, m01} for inner array, and {{...}, {...}} for outer, but why are the outermost braces needed?{}? If it is vector<vector<int>>, need 3 sets also?array is an aggregate. Because inner type is an aggregate itself, you actually can drop all braces, except outer ones: m{m00, m01, m10, m11}initializer_list is better?