How to make a copy of the object in the correct way. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

11th Apr 2022, 3:01 PM
sneeze
sneeze - avatar
3 Answers
+ 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.
12th Apr 2022, 8:37 AM
Mustafa A
Mustafa A - avatar
+ 1
Use a const reference instead.
11th Apr 2022, 9:31 PM
Mustafa A
Mustafa A - avatar
0
When I do that I get the following error. The expression being assigned to 'archiveme' must be constant
12th Apr 2022, 6:51 AM
sneeze
sneeze - avatar