473,386 Members | 1,712 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,386 software developers and data experts.

How to overload operator= to have both deep copy and shallow copy semantics

In other words

Array<int,1> A(5), B(10);
A = B(Range(0,4)); // Statement 1
Array<int,1> C = B(Range(0,4)); // Statement 2

I d like
Statement 1 results in a portion of B's data being copied into A
and
After Statement 2 is executed, the array C is a reference (or alias) to
B's data.
Regards,

Jul 23 '05 #1
1 1531
bl**********@gmail.com wrote:
In other words

Array<int,1> A(5), B(10);
A = B(Range(0,4)); // Statement 1
Array<int,1> C = B(Range(0,4)); // Statement 2
Here operator= is *not* used. It's called _initialisation_ and *not*
assignment. Overloading the assignment operator won't help you. You
need a proper constructor for that.

I d like
Statement 1 results in a portion of B's data being copied into A
and
After Statement 2 is executed, the array C is a reference (or alias) to
B's data.


V
Jul 23 '05 #2

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

Similar topics

16
by: bluekite2000 | last post by:
I want Matrix A(B) to create shallow copy of B but A=B to create deep copy of B. Is that bad design? Why and why not?
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 >>>
11
by: Christoph Boget | last post by:
I've looked through the online documentation and I couldn't find a real explanation as to exacly what is involved with either of the above or exacly what they mean. If someone could point me to...
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)...
26
by: saxenavaibhav17 | last post by:
what is Deep Copy, Shallow copy and Bitwise copy, Memberwise copy? and what is the difference between them? pls help vaibhav
5
by: pauldepstein | last post by:
I recently had a job interview question which I totally failed. (The question seemed excellent from an objective point of view, but having completely failed to do it, my subjective feelings are...
7
by: blangela | last post by:
What does the default assignment operator (compiler supplied assignment operator, sometimes also referred to as the implicit assignment operator or the synthesized assignment operator) do when the...
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...
7
by: vermarajeev | last post by:
Hi guys, I know what a copy constructor and an assignment operator is. I have read that in a copy constructor, deep copy () happens and in assignment operator shallow copy happens. My question...
9
by: George2 | last post by:
Hello everyone, I am wondering the default implementation of assignment operator (e.g. when we do not implement assignment operator in user defined class, what will be returned? temporary...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.