I have a template class that's a simple vector, but this piece of code refuses to compile:
template<int t>
struct Vector {
int pos[t];
Vector(int other[t]) {
for (int i = 0;i < t;++i) {
pos[i] = other[i];
}
}
};
Vector<3> cake = {3,4,5};
This is the error:
Line 11: error: scalar object 'cake' requires one element in initializer
compilation terminated due to -Wfatal-errors.
Why doesn't this work? What's the simplest way to make it work similarly to this?
EDIT:
Neither does this work:
Vector<3> cake({3,4,5});
Isn't that supposed to call a constructor with signature Vector<3>(int[3])
?