Deep Copy and '='

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, Newsgroupians!

I have, perhaps, a simple question regarding deep copy and the assignment
operator. I'm creating a class, and I would like to perform a deep copy of
all the members in an instance of the class. I know I can derive the class
from ICloneable and override the Clone() function. I do this, and I can
accurately create a deep copy of my class.

MyClass c1 = new MyClass(...);
MyClass c2;
c2 = c1.Clone();

This works -- of course -- but I would like to reduce the amount of typing
to just the simple...

c2 = c1;

Many of you may state that this is undesirable, for you may want a reference
at one time or another, but in this specific class whenever I do an
assignment operator, I ALWAYS want a deep copy. Is this possible? Thank you
all.


Trecius
 
Many of you may state that this is undesirable, for you may want a reference
at one time or another, but in this specific class whenever I do an
assignment operator, I ALWAYS want a deep copy. Is this possible? Thank you
all.

No, it's not. You can't override the assignment operator.

Jon
 
I don't think you can do that with classes but you can always try changing
the class to a strcut.



If your requirements allow you to do that, you will be able to accomplish
what you want.
 
Back
Top