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

B

bluekite2000

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,
 
V

Victor Bazarov

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top