Get the address of an object, within the object itself

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 15 13:33:23 PST 2017


On Wednesday, February 15, 2017 21:27:00 Andrew Chapman via Digitalmars-d-
learn wrote:
> Hi all, sorry if this question is silly, but is it possible to
> get the address of an object within the object itself?
>
> e.g.
>
> class Node
> {
>      this()
>      {
>          writeln(&this);  // Doesn't work
>      }
> }
>
> auto node = new Node();
> writeln(&node); // Does work

This does _not_ give you the address of the Node object. It gives you the
address of the reference.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list