Unlike built-in arrays, the library array type does allow assignment. The left-and
right-hand operands must have the same type:
1 2 3 4
array<int, 10> a1 = {0,1,2,3,4,5,6,7,8,9};
array<int, 10> a2 = {0}; // elements all have value 0
a1 = a2; // replaces elements in a1
a2 = {0}; // error: cannot assign to an array from a braced list
Because the size of the right-hand operand might differ from the size of the left-hand
operand, the array type does not support assign and it does not allow assignment
from a braced list of values.
but when i compile it, the code runs perfectly.
is this a compiler extension?
Note:
You can ask g++/clang++ to enforce standards-compliance by adding the flags -std=c++14 -Wall -Wextra -pedantic-errors to the command line. I'm not sure what the equivalent flags are for Microsoft's compiler.
I don't know. The uniform initialization syntax was new in C++11. Perhaps that idea was based off a paper which was later revised before the standard was published.