开发者

C++: Copying to dereferenced pointer

I currently have a weird problem with a program segfaulting but im not able to spot the error. I think the problem boils down to this.

struct S {int a; vector<sometype> b;}
S s1;
// fill stuff into a and b
S* s2 = new S();
*s2 = s1;

Could it be that the final copying is illegal in s开发者_运维知识库ome way? Im really confused right now... Thanks


You will get this behaviour if sometype has a bug in its user defined copy constructor and/or assignment operator. The code you have supplied is perfectly legal.


Sorry, the code looks just fine to me, unless something evil is hidden under 'sometype'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜