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 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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
>>>
|
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)...
|
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...
|
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...
|
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...
|
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:
...
|
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...
|
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
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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...
| |