Reset class member variables

mandel mandel at foobar.com
Fri Sep 7 12:14:03 PDT 2007


Ok, I jumped to early. :/
This method ignores const values that I have set in the ctor:
So, "this() { y = 123; }" would be reset to 0.

Sean Kelly Wrote:
> 
> It's a bit horrifying, but this should work:
> 
> class Foo
> {
>      uint x;
>      char[] name = "world";
> //problematic:
>      const uint y;
>      char[1024] buffer;
> 
>      void reset()
>      {
>          (cast(byte*) this)[0 .. this.classinfo.init.length] =
>              this.classinfo.init[0 .. $];
>      }
> }
> 
> 
> Sean




More information about the Digitalmars-d mailing list