Copying reference types by value

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Wed Apr 17 10:09:27 PDT 2013


On 04/17/2013 06:54 PM, Ali Çehreli wrote:
> I haven't used it anywhere but I did think about this very issue just the other
> day. I thought about defining a takeOver() member function that does what you need:
> 
>   // take over the members of b
>   a.takeOver(b); // b becomes null (or .init?)

Ahh, so you mean that the current members of a get discarded and replaced with
those of b?

> Using takeOver() along with dup(), one can copy state:
> 
>   a.takeOver(b.dup());
> 
> Of course there can be a wrapper function for that. :)

It's an intriguing thought.  How do you get round the issue of private variables
... ?  And what's the benefit over a method like, say,

	a.copyFrom(b);

... which just copies values between corresponding variables?  (Leaving aside
that takeOver has applications of its own -- I mean my question purely in the
context of copying values.)


More information about the Digitalmars-d-learn mailing list