February 06, 2018 Implicit Casting | ||||
---|---|---|---|---|
| ||||
I am trying to make a `Pos` type. But I need it to implicitly cast from an `int[2]`. I am using the `alias this` to get most of what I want but it still doesn't do all an implicit cast can do. What I have now is this: struct Pos { int[2] pos; alias pos this; this (int[2] pos) { this.pos = pos; } } This allows me to implicitly cast from type `Pos` to type `int[2]` but not the other way. I can do a sort of cast when I define a `Pos` (`Pos pos = [2,3]` works). But what I really want it to do is to implicitly cast an `int[2]` to a `Pos`. Is this possible in D? |
February 06, 2018 Re: Implicit Casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan | On 02/06/2018 01:35 PM, Jonathan wrote: > But what I really want it to do is to implicitly cast an `int[2]` to a > `Pos`. > > Is this possible in D? Simply, no. :) Ali |
Copyright © 1999-2021 by the D Language Foundation