+ 1
How to make a copy of the object in the correct way.
I need to make a copy of the current state of the object When pass this object into a method, it looks like a reference and any DoSomething can still modify the object // DoArchive(this); //=======> So I tried creating a variable and copy the object in there //var archiveme = this;//======> //DoArchive(archiveme); //This gives the same result //How to make a copy of the object in the correct way. ? https://code.sololearn.com/cG09vKu0h8Eu/?ref=app
3 Antworten
+ 1
sneeze I have no idea. First time seeing that error. But if you want to make a copy as you initially asked. You will have to implement a copy constructor and a copy operator. Using that you can properly copy the object.
+ 1
Use a const reference instead.
0
When I do that I get the following error.
The expression being assigned to 'archiveme' must be constant