implicit constructors

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


On 11/27/2011 01:54 AM, Timon Gehr wrote:
> 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);
> }

A a = 5;

Does not work though.


More information about the Digitalmars-d mailing list