如果我有这个 struct S { int arr [5]; }; 和我这样做: S s1,s2; .... s1 = s2; 会发生什么? 通常,数组任务是不可能的/允许的。如果我做s1.arr = s2.arr我得到编译器错误。如果我做s1 = s2它编译得很好。并且它似乎是甚至似乎是数组被复制,而不仅仅是指向数组的 起点,至少用g ++。 C和C ++之间的语义有什么不同吗? / David
解决方案David Rasmussen <哒************* @ gmx>在消息中写道 news:40a0fafd
0
174 struct S {arr [5]; }; s1 = s2; 会发生什么? 通常情况下,阵列分配是不可能/不允许的。如果我做s1.arr = s2.arr我得到编译器错误。如果我做s1 = s2它编译得很好。它甚至看起来像数组被复制,而不仅仅是指向数组开始的指针,至少用g ++。 这里的语义是否有任何区别在C和C ++之间?
是的,赋值在C和C ++中复制数组内容。复制构造函数相同的 。
If I have this struct S { int arr[5]; }; and I do this: S s1,s2; .... s1 = s2; what happens? Normally, array assignments aren''t possible/allowed. If I do s1.arr = s2.arr I get a compiler error. If I do s1 = s2 it compiles fine. And it even seems like the array is getting copied, not just the pointer to the start of the array, at least with g++. Is there any difference in semantics here betweeen C and C++? /David
解决方案 "David Rasmussen" <da*************@gmx> wrote in message news:40a0fafd0174 struct S { int arr[5]; }; s1 = s2; what happens? Normally, array assignments aren''t possible/allowed. If I do s1.arr = s2.arr I get a compiler error. If I do s1 = s2 it compiles fine. And it even seems like the array is getting copied, not just the pointer to the start of the array, at least with g++. Is there any difference in semantics here betweeen C and C++?Yes, the assignment copies the array contents, in both C and C++. Same thing for the copy constructor.
更多推荐
使用数组复制struct
发布评论