I want to use initializer lists for my vectors and arrays. Ultimately, I would like to initialize an array of vectors of some class A, but I do not get there while getting weird compiler errors. Here is some code:
#include <vector>
#include <array>
class A {
public:
A(int x_, int y_): x(x_), y(y_) {}
private:
int x;
int y;
};
int main() {
auto data = std::array<int, 3>{0, 1, 2};
auto data2 = std::array<A, 3>{ A(0,0), A(1,1), A(2,2) };
auto data3 = std::vector<std::vector<int>> { {0,0,0}, {1,1,1}, {2,2,2} };
auto data4 = std::array<std::vector<int>, 3> { {0,0,0}, {1,1,1}, {2,2,2} };
//auto data5 = std::array<std::vector<A>, 3> { ??? };
}
The first three examples work perfectly fine. I do not get why the forth example does not compile (using c++17) as it is exactly the same as in the third example. The error is "too many initializer" which I do not get. Everything I tried for the fifth example does not work. Is it even possible?