Hi
I'm trying to create a class that will support a deep copy when using the assignment operator, much like how the string class does it.
Normally speaking, the assignment operator will create a reference copy of the object, which means that both the original and new object point to the same data. I'm trying to emulate what the string class does, which is that the two objects point to different sets of data after the assignment. I know we have the ICloneable interface, but I'd like to avoid using it. Any ideas? There has to be a way. If string can do it, so can we ...
My ideal scenario would be:
I'm trying to create a class that will support a deep copy when using the assignment operator, much like how the string class does it.
Normally speaking, the assignment operator will create a reference copy of the object, which means that both the original and new object point to the same data. I'm trying to emulate what the string class does, which is that the two objects point to different sets of data after the assignment. I know we have the ICloneable interface, but I'd like to avoid using it. Any ideas? There has to be a way. If string can do it, so can we ...
My ideal scenario would be:
Code:
Employee employee1 = new Employee("Joe");
Employee employee2 = employee1;
employee1.Name = "Jane";
// At this point, both employee1.Name and employee2.Name = "Jane". I want this to be employee1.Name = "Jane" and employee2.Name = "Joe".