www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Reset class member variables

Matti Niemenmaa Wrote:

 mandel wrote:

 class Foo
 	uint x;
 	char[] name = "world";
 	const uint y;
 	char[1024] buffer;
 	void reset()
 		scope tmp = new typeof(this);
 		foreach(i, x;  tmp.tupleof)
 			this.tupleof[i] = x;
 The problem is that I have to avoid
 to try to set const values and static arrays.
 How can this be done?

Does "this = new typeof(this);" work?

No, it does have no effect. Btw.: that's the error message I get from dmd: Error: can only initialize const member y inside constructor Error: cannot assign to static array this.buffer
Sep 07 2007