digitalmars.D.learn - this() const
this( const size_t step) const { this.step = step; } Error: cannot modify const/immutable/inout expression this.step Is this the expected behavior? Thanks.
Apr 15 2012
Am 15.04.2012, 21:20 Uhr, schrieb sclytrack <sclytrack hotmail.com>:this( const size_t step) const { this.step = step; } Error: cannot modify const/immutable/inout expression this.step Is this the expected behavior? Thanks.Yep.
Apr 15 2012
On 15/04/2012 21:07, Trass3r wrote:Am 15.04.2012, 21:20 Uhr, schrieb sclytrack <sclytrack hotmail.com>:No it's not: import std.stdio; struct foo { size_t _a; this(const size_t b) const { this._a = b; } } class bar { size_t _a; this(const size_t b) const { this._a = b; } } void main() { const a = new foo(42); const b = new bar(42); writefln("a._a: %d\n", a._a); writefln("b._a: %d\n", b._a); } works as expected. dmd v2.058 -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.ukthis( const size_t step) const { this.step = step; } Error: cannot modify const/immutable/inout expression this.step Is this the expected behavior? Thanks.Yep.
Apr 15 2012
On 04/15/2012 11:04 PM, Simon wrote:On 15/04/2012 21:07, Trass3r wrote:Thanks. That was helpful (no irony). Compiler message was a bit fuzzy. this() const // Here the const modifies the return type // While in normal methods it shouldn't. These "constness baking" seems only to be allowed in constructors.Am 15.04.2012, 21:20 Uhr, schrieb sclytrack <sclytrack hotmail.com>:No it's not: import std.stdio; struct foo { size_t _a; this(const size_t b) const { this._a = b; } } class bar { size_t _a; this(const size_t b) const { this._a = b; } } void main() { const a = new foo(42); const b = new bar(42); writefln("a._a: %d\n", a._a); writefln("b._a: %d\n", b._a); } works as expected. dmd v2.058this( const size_t step) const { this.step = step; } Error: cannot modify const/immutable/inout expression this.step Is this the expected behavior? Thanks.Yep.
Apr 16 2012