Can someone explain why opCast is so limited?

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 6 11:27:58 PDT 2007


"Nathan Reed" wrote
> Steven Schveighoffer wrote:
>> Question #2:  Is there a way to cast a basic type to a struct/class?
>
> D 2.0 will have an opImplicitCastFrom function, so you can write e.g.
>
> struct myType {
>     myType opImplicitCastFrom (long l) { ... }
> }
>
> This isn't implemented yet, but is planned.

Excellent!  I'm assuming since there is an argument, overloading is 
possible?  Also, the 'implicit' suggests that you can do something like:

long l;
myType x = l;

???

-Steve 




More information about the Digitalmars-d-learn mailing list