15

One can assign a struct to another, which results in copying all the values from struct to another:

struct
{
    int a, b, c;
} a, b;

...
a = b;

But why are arrays not assignable like that:

int a[3], b[3];
...
a = b;

Because, strictly speaking, are structs just arrays with variable sized elements, so why is that not allowed? This kind of assignment is unused anyway. Sure, it may seem like only the addresses are involved, but one can easily copy arrays that way ("statically").

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Kapichu
  • 3,346
  • 4
  • 19
  • 38
  • 1
    There's an easy way around it: use `std::array`. – chris Aug 10 '14 at 16:35
  • That would also be convenient because you could assign strings to char arrays (not only pointers!) `char array[4] = "hi!";`, but also `array = "bye";`! – Kapichu Aug 16 '14 at 16:35

0 Answers0