Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn
I want to get address of object Cfoo in constructor. Whether it is possible? now: - class Cfoo { void* adrThis; void saveThis(void* adr) { adrThis = adr; } } ... Cfoo foo = new Cfoo(); foo.saveThis(&foo); shall be -- class Cfoo { void* adrThi

Re: Get address of object in constructor.

2016-03-13 Thread WebFreak001 via Digitalmars-d-learn
On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote: I want to get address of object Cfoo in constructor. Whether it is possible? class Cfoo { void* adrThis; this() { adrThis = cast(void*) this; } } ... Cfoo foo = new Cfoo(); "this" should work (pun int

Re: Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn
On Sunday, 13 March 2016 at 15:49:20 UTC, WebFreak001 wrote: On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote: I want to get address of object Cfoo in constructor. Whether it is possible? class Cfoo { void* adrThis; this() { adrThis = cast(void*) this;

Re: Get address of object in constructor.

2016-03-13 Thread WebFreak001 via Digitalmars-d-learn
On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote: Cfoo foo = new Cfoo(); foo.saveThis(&foo); However note that this is not the same as that function. cast(void*)this and &this are 2 different things. So if you want to do the same as saveThis just do void* thisAddr = cast(void*) &this; ins

Re: Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn
On Sunday, 13 March 2016 at 16:02:07 UTC, WebFreak001 wrote: However note that this is not the same as that function. cast(void*)this and &this are 2 different things. So if you want to do the same as saveThis just do void* thisAddr = cast(void*) &this; instead void* thisAddr = cast(void*) &t

Re: Get address of object in constructor.

2016-03-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 13 March 2016 at 16:16:55 UTC, MGW wrote: void* thisAddr = cast(void*) &this; This doesn't really make sense anyway, this is a local variable, you want to do cast(void*) this in a class if you need the address (which btw, you shouldn't actually, the reference itself ought to be en