Re:Writing comments about pointer ownership
by nice_byte on Sunday August 23, 2015 @03:49AM
(#10104968)
Someone brought up this point during another discussion and initially I agreed with them. However, someone else suggested that if the function has more parameters, an exception might happen when passing the arguments for the other parameters, so the transfer of ownership won't happen, but the caller will have already lost the ownership. Passing by rvalue reference means the caller retains ownership until the very last possible moment.
[ Parent
| on HN ]
Re:Writing comments about pointer ownership
by merogin on Sunday August 23, 2015 @04:08AM
(#10104999)
Do you mean something like this? http://ideone.com/8tPPHy
Re:Writing comments about pointer ownership
by nice_byte on Sunday August 23, 2015 @04:21AM
(#10105008)
Yes. It seems to work, but it might be a coincidence. The order of argument evaluation is undefined. It might be that the exception gets thrown before the ownership is transferred, but it's just luck. I have modified your example a bit, to better trace what's happening: http://ideone.com/tgh0xe