tags:

views:

57

answers:

2

Hi. 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 some way? Im really confused right now... Thanks

+2  A: 

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.

anon
actually sometype is a shared_ptr with proper copyctr and assop
bbb
@bbb Then the bug is probably in the class the shared pointer is pointing to - possibly in its destructor. You need to post a complete example that illustrates the problem.
anon
thx for your response. i was able to switch to boost::shared_ptr and it seems to make the problem go away (was using custom shptr-impl before).
bbb
A: 

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

Pavel Radzivilovsky