c++ does implicit copy constructor copy array member variable?

eugene picture eugene · Apr 18, 2011 · Viewed 33.9k times · Source

Possible Duplicate:
How are C array members handled in copy control functions?

I would guess implicit copy constructor (generated by compiler) would copy pointer if member variable is declared as pointer.

I'm not sure what happens to array member variable.

Does implicit copy constructor copy array member correctly? How about assignment operator?

For instance:

char mCharArray[100];
int mIntArray[100];   

Would the mCharArray mIntArray be copied correctly?

Answer

user2100815 picture user2100815 · Apr 18, 2011

Yes and yes is the answer. This is also true of structs in C.

typedef struct {
    int a[100];
} S;

S s1;
s1.a[0] = 42;
S s2;
s2 = s1;    // array copied