Question about pure functions

Bienlein jeti890 at web.de
Mon Sep 16 00:01:47 PDT 2013


Hello,

ich habe a pure method bar() in a class Foo:

class Foo {
	int i = 0;
	
	void bar() pure {
	    i++;
	}	
}

main() {
	auto foo = new Foo();
	foo.bar()	
}

The pure method bar changes the inst var i. Nevertheless, the
code above compiles and runs which I find confusing. I assumed
that changing an inst var by a pure function is considered
creating a side efect. But the compiler has no problems with this.

Am I getting something wrong here? Thanks for any hints.
Regards, Bienlein


More information about the Digitalmars-d-learn mailing list