Reset class member variables
Matti Niemenmaa
see_signature at for.real.address
Fri Sep 7 11:30:56 PDT 2007
mandel wrote:
> Hi,
>
> I have some big classes with lots of member variables
> that need to be reset to theire initial value.
> Therefore I thought about a more reliable way to
> accomplish this, because it's hard to keep track
> of variables I have added.
> It also looks bloated to assign all values manually.
>
> class Foo
> {
> uint x;
> char[] name = "world";
> //problematic:
> 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?
--
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
More information about the Digitalmars-d
mailing list