Meaning of pure member function

H. S. Teoh hsteoh at
Mon Jan 16 21:18:01 PST 2012

The following code compiles without error:

	class C {
		int x;

		// what does 'pure void' mean??
		pure void f() {
			x++;		// why is this legal?

What does 'pure' mean when applied to a member function? Based on
Andrei's book, 'pure' means that the function's result depends only on
its input. And based on the fact this code compiles, I deduced that
'this' is included as part of the function's input.

However, the function is clearly changing one of its inputs (changing a
member of 'this'). Furthermore, what on earth is 'pure void' supposed to
mean and why does the compiler accept it?

Changing the function to read:

	pure int f() { return x++; }

also compiles without any complaint from the compiler. Yet calling
writeln() from within f() produces an error. Why?


Computerese Irregular Verb Conjugation: I have preferences.  You have
biases.  He/She has prejudices. -- Gene Wirchenko

More information about the Digitalmars-d-learn mailing list