473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Deep Copy and '='

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
Aug 14 '07 #1
2 1262
On Aug 14, 3:54 pm, Trecius <Trec...@discussions.microsoft.comwrote:

<snip>
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

Aug 14 '07 #2
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.

"Trecius" <Tr*****@discussions.microsoft.comwrote in message
news:86**********************************@microsof t.com...
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

Aug 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tony Johansson | last post by:
Hello! I'm reading in a book about C++ and that is something that sound strange. It says "Pointers have reference-assignment semantics similar to those in Java. For example, after the...
2
by: Alex | last post by:
Entering the following in the Python shell yields >>> help(dict.copy) Help on method_descriptor: copy(...) D.copy() -> a shallow copy of D >>>
4
by: fperfect13 | last post by:
Hi, I wanted to perform a deep copy of an array. Searching on google I ran into different opinions : C# Interview Questions (http://blogs.wwwcoder.com/tsvmadhav/archive/2005/04/08/2882.aspx)...
4
by: Dennis | last post by:
I have several Data Structures, say "mystruct" which contain arrays of bytes, other structures, etc. I then dimension a variable (var1) as "mystruct" and set the various elements var1 to data. I...
6
by: Desmond Cassidy | last post by:
Hi, I'm sure this has been asked several times before but I'll risk it ;-) If I wish to save an Arraylist to another Arraylist and work on te original without affecting the contents of the new...
5
by: BenW | last post by:
Hello, What is the easiest way to make "deep copy" of my Hashtable? How about with other Collection classes in C#, any documents available? I don'r actually understand why Framework's...
2
by: bonk | last post by:
I have come across the need to distinguish between the creation of a deep and a shallow copy and with great interest I have read this article: ...
13
by: blangela | last post by:
I have decided (see earlier post) to paste my Word doc here so that it will be simpler for people to provide feedback (by directly inserting their comments in the post). I will post it in 3 parts...
4
by: shuisheng | last post by:
Dear All, Is there any easy way to make sure all my object copies are deep copy or shallow copy? I do not like to implement it in each class one by one. Thanks, Shuisheng
3
by: raylopez99 | last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep cloning versus shallow cloning. The scanned pages of this book are found here: http://www.sendspace.com/file/mjyocg (Word...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.