WeakRefs for a CPP->D wrapper

Tobias Pankrath tobias at pankrath.net
Sat Jan 11 14:26:26 PST 2014


On Saturday, 11 January 2014 at 20:38:33 UTC, Abdulhaq wrote:
> On Saturday, 11 January 2014 at 20:17:14 UTC, Tobias Pankrath 
> wrote:
>>
>> class X {};
>> X x;
>>
>> x is an reference to an instance of X, with other words a 
>> pointer without arithmetic but with syntax sugar. &x will take 
>> the address of this pointer/reference. If you want the address 
>> of the actual instance, you can use cast(void*) for example.
>
> Hi Tobias, can casting the address to void* make a difference 
> to its value?
>

No, try this:
import std.stdio;
class X {}
void foo(X x) { writeln(cast(void*) x); }

void main() {
          X x; // null reference by default.
          writeln(cast(void*) x);
          foo(x);

          x = new X;
          writeln(cast(void*) x);
          foo(x);
}



More information about the Digitalmars-d-learn mailing list