Suppose I have a class called "Person" Each "Person" has neighbors - represented by a collection - whose house addresses are the physical addresses within memory on the heap. If one person moves to a new address, another person immediately takes their place. How do I make such a move happen in code?
Suppose, for example, that Amy has two neighbors, Bob and Carol. Bob moves out and Dan is to move in. As a result, Amy's neighbor collection should now point to Dan when we give it a key or index related to Bob's old house.
I wrote the following code for a basic conversion from one user-defined class to another. However, the compiler complained that there is "no matching function for call to 'swap'".
I wrote the following code for a basic conversion from one user-defined class to another.
This is a different use-case than the one presented in the OP. Swapping isn't appropriate here. That entire function looks questionable. Don't gratuitously use new.