Casting random type to random struct - is this a bug?
rumbu via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 16 02:52:01 PDT 2015
On Wednesday, 15 July 2015 at 15:58:17 UTC, Daniel Kozák wrote:
>
> On Wed, 15 Jul 2015 15:45:43 +0000
> "rumbu" <rumbu at rumbu.ro> wrote:
>
>> struct S { int a, b; }
>> auto s = cast(S)10;
>> //compiles and sets s.a to 10.
>>
>> It works also for any other type, if the structure contains a
>> member of that type in the first position.
>>
>> Is this normal behaviour?
>
> Yes, this is OK
>
> If you need to cast against diferent types you can try pointers:
>
In fact I'm trying to overload the cast operator in this case, I
was surprised about the default casting since I didn't find any
reference to this behaviour, nor in TDPL, nor online.
Since UFCS is not allowed in operator overloading I wonder if
this is possible.
More information about the Digitalmars-d-learn
mailing list