opCast cannot implicitly convert a.opCast of type X to Y

Nathan S. no.public.email at example.com
Tue Feb 13 12:12:30 UTC 2018


On Monday, 12 February 2018 at 02:05:16 UTC, aliak wrote:
> struct B(T) {
>     T t;
> }
>
> struct A(T) {
>     T t;
>     auto opCast(U)() {
>         return B!U(cast(U)t);
>     }
> }
>
> void main() {
>     auto a = A!int(3);
>     auto b = cast(float)a; // error
> }

Having the result of "cast(float) a" not be a float would be evil.


More information about the Digitalmars-d-learn mailing list