Implementing .dup / clone for class hierarchies
Bill Baxter
dnewsgroup at billbaxter.com
Sun Dec 16 16:12:20 PST 2007
Bill Baxter wrote:
> guslay wrote:
>> Bill Baxter Wrote:
> For some reason everyone seemed to like Mikola's suggestion of 'clone'
> for deep copy and 'dup' for shallow copy, but the odd thing about that
> is that .dup on built-in arrays is a deep copy.
I realized this isn't quite true. .dup on arrays is depth=1, rather
than truly "deep" (depth=N) or shallow (depth=0). So maybe Mikola was
right.
We can take 'dup' to mean "copy one more level than you'd get from the
rudimentary assignment: a = b". So for built-in arrays dup means copy
the stuff pointed to by ptr, but for a class, stuff pointed to by a ptr
member wouldn't be copied.
--bb
More information about the Digitalmars-d-learn
mailing list