implicit constructors

Timon Gehr timon.gehr at gmx.ch
Sat Nov 26 16:54:16 PST 2011


On 11/27/2011 12:14 AM, Trass3r wrote:
> anyone?

kk.

struct A{
     struct S{A opAssign(int rhs){return *(cast(A*)&this)=A(rhs);}}
     union{
         struct{ // members
             int store;
         }
         S _x;   // dummy struct
     }
     this(int a) {
         store = a << 16;
         //...
     }
     alias _x this;
}

void main(){
     A x;
     x = 2;
     assert(x.store == 2 << 16);
}


More information about the Digitalmars-d mailing list