Array declaration and initialization

When I try to set an array in this way

1
2
3
4
5
int num[4];
...
if (foobar == 1) num = { 0, 1, 2, 3 };
else num = { 4, 5, 6, 7 };
...


the compiler raises this error:

error: Assigning to an array from an initializer list

How do I properly set up my array?

Thanks in advance
You can do it like that if you use std::array.
1
2
3
4
5
6
int num[4];
std::array<int, 4> num;
...
if (foobar == 1) num = { 0, 1, 2, 3 };
else num = { 4, 5, 6, 7 };
...

Topic archived. No new replies allowed.