mutable keyword

Jack Applegame via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 20 11:23:26 PDT 2016


On Friday, 20 May 2016 at 17:28:55 UTC, Namespace wrote:
> But you can cheat:
You can just cast const away:
struct A {
	int id = 0;
	
	this(int id) {
		this.id = id;
	}
	
	void change() const {
		(cast() id)++;
	}
}

void main() {
	import std.stdio;
	
	A a = A(42);
	a.change();
	
	writeln(a.id);
}


More information about the Digitalmars-d-learn mailing list