Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDaDweeDow

Posted 13 February 2013 - 03:53 PM

yeah that's a no op assignment.  So node1 = node2 doesn't do anything.  Not sure a memcpy(this, &copy, sizeof(Node)) is legal, probably better to just assign all the fields.  You don't need a deep copy though, at least not for this purpose, you could just copy the pointers, since the old copy is going to be dead in a nanosecond.  

 

Edit:

whoops, I realized that was bad advice.  If the destructor of frees an allocated resource, you are going to be dereferencing an invalid pointer (probably, unless that memory gets reused) when you later try to use the copy.  Sorry about that, hope it didn't cause any problems.  


#2DaDweeDow

Posted 13 February 2013 - 02:10 PM

yeah that's a no op assignment.  So node1 = node2 doesn't do anything.  Not sure a memcpy(this, &copy, sizeof(Node)) is legal, probably better to just assign all the fields.  You don't need a deep copy though, at least not for this purpose, you could just copy the pointers, since the old copy is going to be dead in a nanosecond.  


#1DaDweeDow

Posted 13 February 2013 - 02:09 PM

yeah that's a no op assignment.  So node1 = node2 doesn't do anything.  Not sure a memcpy(this, &copy, sizeof(Node)) is legal, probably better to just assign all the fields.  You don't need a deep copy though, at least not here for this, you could just copy the pointers, since the old copy is going to be dead in a nanosecond.  


PARTNERS