I created an array template for my personal use.
template <typename T, int size>
struct Vector {
T data[size];
};
I tried to intialize the data like so:
Vector<unsigned char, 10> test;
test.data[] = {0,1,2,3,4,5,6,7,8,9};
My compiler ended up complaining something about “expected expression.” Does anyone know what I’m doing? I want to be able to use this style of initialization where you give it the entire array definition at once instead of using a for loop to init the elements individually.
Since your class is an aggregate, you can initialize it with the usual brace syntax:
The exact same thing applies to
std::array<int, 3>.