Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to overload operator= to have both deep copy and shallow copy semantics

Reply
Thread Tools

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

 
 
bluekite2000@gmail.com
Guest
Posts: n/a
 
      06-24-2005
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,

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-24-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to implement a deep copy or shallow copy? shuisheng C++ 4 12-17-2006 08:40 AM
what is Deep Copy, shallow copy and bitwises copy.? saxenavaibhav17@gmail.com C++ 26 09-01-2006 09:37 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
deep and shallow copy Tony Johansson C++ 5 05-19-2005 04:13 PM
deep/shallow copy - constructor v Object.copy() VisionSet Java 8 04-29-2004 10:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57