Casting to union type?

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 26 03:49:12 PDT 2014


On Tuesday, 26 August 2014 at 02:33:25 UTC, cc wrote:
> vec2 a = vec2(1.0, 2.0); // fine
> vec2 b;
> b = [3.0, 4.0]; //fine
> vec2 c = [5.0, 6.0]; // cannot cast float[] to vec2

There is currently no implicit for aggregates except using `alias 
this`. But in your example, it's a construction, not an 
assignment, so you need to write an appropriate constructor 
`this(float[])` analogous to `opAssign(float[])`.


More information about the Digitalmars-d-learn mailing list