4 ms·
The C++ implementation of swap given is wrong. SomeType temp = arg1; This would do a deep copy of the object pointed to by the ref arg1. What is intended is p
by banachtarski 12y ago
The C++ implementation of swap given is wrong.
SomeType temp = arg1;
This would do a deep copy of the object pointed to by the ref arg1. What is intended is probably
SomeType& temp = arg1;
- jjnoakes 12y agoNo, the article was right. You can't do a generic swap without 3 deep copies. If you change temp to be a reference, then once you do "arg1 = arg2", you just lost any way to get arg1's value back.