c++ 隐式复制构造函数是否复制数组成员变量?

可能重复:
复制控制函数中如何处理C数组成员?

如果成员变量被声明为指针,我猜想隐式复制构造函数(由编译器生成)会复制指针.

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?

例如:

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

mCharArray mIntArray 会被正确复制吗?

Would the mCharArray mIntArray be copied correctly?

推荐答案

答案是肯定的.C 中的结构也是如此.

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

相关文章