digitalmars.D.learn - Implicit Casting
- Jonathan (18/18) Feb 06 2018 I am trying to make a `Pos` type. But I need it to implicitly
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/6) Feb 06 2018 Simply, no. :)
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?
Feb 06 2018
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
Feb 06 2018