On Wednesday, 22 November 2017 at 15:27:27 UTC, Dukc wrote:
It's worth noting that you will still be passing different addresses to foo(void*) because classes are reference types in D (structs are not). In the constructor you're passing the address of the class object itself, but in the main function you're passing the address of the reference.

No, in both cases, if you do as I say, you will be passing the same address.

You cast the reference itself. Do NOT use the & operator at any point with class objects in D (unless you legit know what you are doing). Just plain cast it:

`cast(void*) this` // ok. gets address of class object itself
`Object o; foo(cast(void*) o);` // also ok, does same thing

`cast(void*) &this` // NOT OK! DO NOT DO THIS address of a local
`cast(void*) &o`    // NOT OK! DO NOT DO THIS address of a local

Reply via email to