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!
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:
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 {
> >>
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 {
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 =
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'...