Re: Can't modify this

2014-07-02 Thread Maxim Fomin via Digitalmars-d-learn
On Saturday, 28 June 2014 at 20:40:21 UTC, Ary Borenszweig wrote: This doesn't work: class Foo { this() { this = new Foo; } } Error: Cannot modify 'this' However you can do this: class Foo { this() { auto p = &this; *p = new Foo(); } } It even changes the value of this!

Re: Can't modify this

2014-06-30 Thread via Digitalmars-d-learn
On Saturday, 28 June 2014 at 21:39:35 UTC, Ary Borenszweig wrote: On 6/28/14, 6:21 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Sat, Jun 28, 2014 at 05:40:19PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: This doesn't work: class Foo { this() { this = new Foo; } } Error:

Re: Can't modify this

2014-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 28, 2014 at 06:39:33PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: > On 6/28/14, 6:21 PM, H. S. Teoh via Digitalmars-d-learn wrote: > >On Sat, Jun 28, 2014 at 05:40:19PM -0300, Ary Borenszweig via > >Digitalmars-d-learn wrote: > >>This doesn't work: > >> > >>class Foo { > >>

Re: Can't modify this

2014-06-28 Thread Ary Borenszweig via Digitalmars-d-learn
On 6/28/14, 6:21 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Sat, Jun 28, 2014 at 05:40:19PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: This doesn't work: class Foo { this() { this = new Foo; } } Error: Cannot modify 'this' However you can do this: class Foo {

Re: Can't modify this

2014-06-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 28, 2014 at 05:40:19PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: > This doesn't work: > > class Foo { > this() { > this = new Foo; > } > } > > Error: Cannot modify 'this' > > However you can do this: > > class Foo { > this() { > auto p = &this; > *p =

Can't modify this

2014-06-28 Thread Ary Borenszweig via Digitalmars-d-learn
This doesn't work: class Foo { this() { this = new Foo; } } Error: Cannot modify 'this' However you can do this: class Foo { this() { auto p = &this; *p = new Foo(); } } It even changes the value of this! Should that compile? I mean, it's the same as modifying 'this'...