开发者

C++: Copying to dereferenced pointer

开发者 https://www.devze.com 2023-01-02 15:53 出处:网络
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.

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

精彩评论

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

关注公众号