copying the targets of pointers

Artur Skawina art.08.09 at gmail.com
Fri Jul 27 09:47:41 PDT 2012


On 07/27/12 18:11, 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"

Exactly the same, there's no difference between C and D pointers, except for classes.

> Here is the context of what I'm trying to do:
> 
> ----
> struct S
> {
>   struct Payload
>   {}
>   Payload payload;
> 
>   @property
>   typeof(this) dup()
>   {
>     typeof(this) ret;
>     if(payload)
>     {
>       ret.payload = new Payload;
>       ret.payload = payload; //Copies the payload? The pointer?

'ret.payload' is 'S'; 'new Payload' is '*S'...

If you meant 'Payload* payload;', then just the pointer is copied.

artur


More information about the Digitalmars-d-learn mailing list