Re: Returning this from a const member

2010-03-20 Thread Robert Clipsham
On 21/03/10 00:18, bearophile wrote: Robert Clipsham: Why is this? It's not a hard question. This code compiles: class Foo { const(Foo) myFoo() const { return this; } } void main() { auto f = new Foo; } It's just in a const function the "this" is const, so if you want

Re: Returning this from a const member

2010-03-20 Thread bearophile
Robert Clipsham: > Why is this? It's not a hard question. This code compiles: class Foo { const(Foo) myFoo() const { return this; } } void main() { auto f = new Foo; } It's just in a const function the "this" is const, so if you want to return it, then you have to use a "con

Returning this from a const member

2010-03-20 Thread Robert Clipsham
According to http://digitalmars.com/d/2.0/const3.html: Const member functions are functions that are not allowed to change any part of the object through the member function's this reference. With the following code: class Foo { Foo myFoo() const {