this() const

Simon s.d.hammett at gmail.com
Sun Apr 15 14:04:11 PDT 2012


On 15/04/2012 21:07, Trass3r wrote:
> Am 15.04.2012, 21:20 Uhr, schrieb sclytrack <sclytrack at 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.

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.uk


More information about the Digitalmars-d-learn mailing list