copying the targets of pointers

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 27 10:51:45 PDT 2012


On Friday, July 27, 2012 10:32:07 Ali Çehreli wrote:
> On 07/27/2012 09:11 AM, monarch_dodra wrote:
>  > This is going to sound stupid, but how do you have two pointers' targets
>  > copy each other? since pointers are used like reference types, how do
>  > you write the C++ equivalent of "*p1 == *p2"
> 
> The type must provide a function to make a copy of itself. Since arrays
> have .dup, that may be a suitable name:
> 
>     auto newObject = object.dup;

That's only if you're dealing with references or if the pointers point to 
structs which are reference types (or if they're pointers to arrays, which 
would be a bit weird). If you're dealing with a built-in type or value type 
structs, then no dup is necessary.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list