How to define opCast from native types
Cheery
cherry at dream.land
Fri Feb 7 10:55:02 PST 2014
> The line above is an explicit object construction. That's why D
> allows that syntax. Unlike C++, there is no implicit conversion
> when passing to a function:
>
> void func(Integer i)
> {}
>
> func(1L); // Does not call the constructor
>
Ali
Sorry for not being clear in my first port. I was not referring
to implicit vs explicit conversion. I would also like to avoid
explicit call to constructors.
For example I would like to avoid.
long ll;
Integer foo = ll;
But I want something like this to be enabled.
long ll;
Integer foo = cast(foo) ll;
Unfortunately for casting of native types, D seems to rely only
on constructor functions.
Regards
- Cherry
More information about the Digitalmars-d
mailing list